到目前为止,我们一直在 Symfony2 中使用自定义身份验证系统。我们现在正在扩展我们的功能,它已经到了 FOSUserBundle 将节省时间的阶段。
我已经用 Composer 安装了 FOSUserBundle 并将其添加到 appKernel.php 中。
关于实体,由于已经有一个 User 实体,我刚刚删除了 FOS 包中 AbstractUser 实体已经具有的字段并对其进行了扩展:
use FOS\UserBundle\Entity\User as BaseUser;
...
class User extends BaseUser
我去更新与教义模式:模式:更新--force 并得到以下内容:
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'lifemirror.user' already exists.
好吧,是的,用户表已经存在,但是该命令应该更新它。我更改了用户实体中的表名并执行操作--dump-sql
以查看发生了什么,它似乎保留了表但删除了结构:
ALTER TABLE user DROP email, DROP username, DROP password, DROP invitation_code, DROP picture_file;
所以我认为 User 实体可能正在其他地方使用,但我不确定在哪里。
在 Pazi 的建议下,我安装了学说迁移包并尝试创建一个迁移。它生成以下内容
/**
* Auto-generated Migration: Please modify to your need!
*/
class Version20130701134939 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("CREATE TABLE film_today (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, id_user INT DEFAULT NULL, suggest_date DATE DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHA$
$this->addSql("CREATE TABLE user1 (id INT AUTO_INCREMENT NOT NULL, firstname VARCHAR(255) DEFAULT NULL, lastname VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, birthdate DATE DEFAULT NULL, PRIMARY KEY(id)) DEFAU$
$this->addSql("DROP TABLE cinema");
$this->addSql("DROP INDEX id_user ON session");
$this->addSql("ALTER TABLE job CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE cinema cinema INT NOT NULL, CHANGE name name LONGTEXT NOT NULL, CHANGE status status VARCHAR(10) NOT NULL");
$this->addSql("ALTER TABLE film_location CHANGE screening_description screening_description VARCHAR(255) DEFAULT NULL");
$this->addSql("ALTER TABLE report_film CHANGE id_user id_user INT DEFAULT NULL, CHANGE id_film id_film INT DEFAULT NULL");
$this->addSql("DROP INDEX email ON user");
$this->addSql("ALTER TABLE user DROP email, DROP username, DROP password, DROP invitation_code, DROP picture_file");
$this->addSql("ALTER TABLE film_today_vote CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE id_film_today id_film_today INT DEFAULT NULL, CHANGE id_user id_user INT DEFAULT NULL, CHANGE vote_date vote_date DATE DEFAULT NULL");
$this->addSql("ALTER TABLE video CHANGE timestamp timestamp DATETIME NOT NULL");
}
public function down(Schema $schema)
{
// this down() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("CREATE TABLE cinema (id INT AUTO_INCREMENT NOT NULL, username LONGTEXT NOT NULL, usernameCanonical LONGTEXT NOT NULL, email LONGTEXT NOT NULL, password LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET u$
$this->addSql("DROP TABLE film_today");
$this->addSql("DROP TABLE user1");
$this->addSql("ALTER TABLE film_location CHANGE screening_description screening_description LONGTEXT NOT NULL");
$this->addSql("ALTER TABLE film_today_vote CHANGE id id INT NOT NULL, CHANGE id_film_today id_film_today INT NOT NULL, CHANGE id_user id_user INT NOT NULL, CHANGE vote_date vote_date DATETIME NOT NULL");
$this->addSql("ALTER TABLE job CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL, CHANGE cinema cinema INT UNSIGNED NOT NULL, CHANGE name name LONGTEXT DEFAULT NULL, CHANGE status status VARCHAR(255) NOT NULL");
$this->addSql("ALTER TABLE report_film CHANGE id_user id_user INT NOT NULL, CHANGE id_film id_film INT NOT NULL");
$this->addSql("CREATE INDEX id_user ON session (id_user)");
$this->addSql("ALTER TABLE user ADD email VARCHAR(255) DEFAULT NULL, ADD username VARCHAR(255) DEFAULT NULL, ADD password LONGTEXT DEFAULT NULL, ADD invitation_code VARCHAR(255) DEFAULT NULL, ADD picture_file LONGTEXT DEFAULT $
$this->addSql("CREATE UNIQUE INDEX email ON user (email)");
$this->addSql("ALTER TABLE video CHANGE timestamp timestamp DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL");
}
}
我认为这突出了同样的问题——用户实体没有被正确扩展。