我想在我的网站上创建一个简单的用户管理。我遵循了Maker-Bundle的教程,但是如果我运行命令doctrine:schema:update --force,则会得到一个错误:
An exception occurred while executing 'CREATE TABLE user (id INT
AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT
NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX
UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET
utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near 'JSON NOT
NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX
UNIQ_8D93D649E7927C7' at line 1这是我的用户实体
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
}我已经尝试过几个教程,但是每次都会发生这个错误,似乎与“角色”字段的数据类型有关。就像在其他教程中一样,我也尝试了json_array和array,但是同样的错误。我在Windows10上使用XAMPP服务器和Windows10数据库。
发布于 2018-12-18 09:20:02
您运行的是什么版本的MySQL?在MySQL 5.7.8中引入了JSON数据类型
XAMPP默认附带最新版本的MariaDB,10.1.37,它不支持JSON数据类型(从10.2.6版本开始)
您可以卸载MariaDB并从https://dev.mysql.com/downloads/mysql/安装MySQL或从这里安装MariaDB的最新版本https://downloads.mariadb.org/。
发布于 2019-10-21 07:54:46
您可能需要检查mysql版本和,确保它与中指定的版本相同。
Json类型与MySql 5.6及更低版本不兼容,默认情况下symfony配置为5.7。
如果您使用5.6或更少的版本运行,则更新config/packages/prinine.yaml,symfony应该负责其余的操作。
https://stackoverflow.com/questions/53829553
复制相似问题