Symfony2主义架构更新失败 [英] Symfony2 Doctrine schema update fails

查看:69
本文介绍了Symfony2主义架构更新失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地计算机上创建了数据库.将项目移到服务器后,我从本地导入了备份(因为那里有一些重要数据).

I created database on my local machine. After moving my project to server I imported backup from local (because I had some important data there).

现在,当我尝试更新服务器上的架构时,它会提供以下输出:

Now,when I'm trying to update schema on my server it gives my this output:

php app/console doctrine:schema:update --force
Updating database schema...





  [Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException]                                                                                                             
  An exception occurred while executing 'ALTER TABLE golf_course ADD CONSTRAINT FK_EC96E162F1503E2B FOREIGN KEY (golf_id) REFERENCES golf (id)':                               
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`GolfFairway`.`#sql-3fae_7ccf1`, CONSTRAINT `FK_EC9  
  6E162F1503E2B` FOREIGN KEY (`golf_id`) REFERENCES `golf` (`id`))                                                                                                             






  [Doctrine\DBAL\Driver\PDOException]                                                                                                                                          
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`GolfFairway`.`#sql-3fae_7ccf1`, CONSTRAINT `FK_EC9  
  6E162F1503E2B` FOREIGN KEY (`golf_id`) REFERENCES `golf` (`id`))                                                                                                             






  [PDOException]                                                                                                                                                               
  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`GolfFairway`.`#sql-3fae_7ccf1`, CONSTRAINT `FK_EC9  
  6E162F1503E2B` FOREIGN KEY (`golf_id`) REFERENCES `golf` (`id`))                                                                                                             

为什么会这样?有解决方案吗?

Why this happens ? Is there a solution ?

推荐答案

您的问题是您想使用现有约束来修改表.我看到了两种解决方案:

Your problem is that you want to modify a table with existing constraint. I see two solutions:

如果您是开发人员,则可以重建数据库

If you are in dev, you can rebuild your database

doctrine:database:drop --force
doctrine:database:create
doctrine:schema:create

如果您正在生产中,它会稍微复杂一些.

If you're in production it's a little more complicated.

我看到的一个解决方案是,您可以创建一个命令来保存数据,删除要更改的表中的数据,修改架构,更改表后重新加载数据.视更改而定,此过程不应超过2-3个小时.只要确保您有备份,以防您的命令向南移动即可.

One solution I see is that you could create a command to save your data, delete the data in the tables you want to alter, modify your schema, reload the data once your table is altered. Depending on the changes, it shouldn't take more then 2-3 hours. Just make sure you have a backup in case your command goes south.

这篇关于Symfony2主义架构更新失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆