无法在Symfony中将实体与数据库同步

时间:2016-01-04 19:50:47

标签: symfony

我开始探索Symfony,在通过导入this sql脚本创建架构并按照这些命令创建实体后:

va_arg

命令:

Importing mapping information by generating the metadata files:

    $ php app/console doctrine:mapping:import --force AcmeBlogBundle xml

Build related entity classes:
    -> Generates entity classes with annotation mappings
    $ php app/console doctrine:mapping:convert annotation ./src
    $ php app/console doctrine:generate:entities AcmeBlogBundle

因以下错误而失败:

$ php app/console doctrine:schema:update --force

生成的转储文件是:

[Doctrine\DBAL\Exception\DriverException]                                                                              
  An exception occurred while executing 'ALTER TABLE writtings CHANGE id id INT AUTO_INCREMENT NOT NULL':                
  SQLSTATE[HY000]: General error: 1025 Error on rename of './amimusa/#sql-425_5e' to './amimusa/writtings' (errno: 150)                                                                                                 
  [Doctrine\DBAL\Driver\PDOException]                                                                                    
  SQLSTATE[HY000]: General error: 1025 Error on rename of './amimusa/#sql-425_5e' to './amimusa/writtings' (errno: 150)  
  [PDOException]                                                                                                         
  SQLSTATE[HY000]: General error: 1025 Error on rename of './amimusa/#sql-425_5e' to './amimusa/writtings' (errno: 150)  

任何人都可以帮我理解更新失败的原因? 此外,我无法弄清楚为什么这些操作是必需的,因为所有操作都是从头开始创建的。

1 个答案:

答案 0 :(得分:0)

Cerad评论:

  

逆向工程的东西并不完美。学说喜欢   事物以自己的方式定义。我建议删除数据库   使用doctrine:schema:create以像doctrine所希望的那样重建它   是

$ php app/console doctrine:schema:drop --force
$ php app/console doctrine:schema:create

修复了问题。