dou29106 2011-05-13 15:56
浏览 64
已采纳

Symfony迁移失败

I just changed my schema for a symfony project I'm working on (added a table and a few columns) and ran the following two commands:

php symfony doc:generate-migrations-diff
php symfony doc:migrate

Previously this has worked without any problems, but this time it freaked out. I accidently gave two tables the same name, which it reasonably failed on, but now that I fixed my schema file it still won't work. It produces the following errors:

  The following errors occurred:                                                                                                                                                                                                                                                                                           

   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_images' already exists. Failing Query: "CREATE TABLE media_images (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_events' already exists. Failing Query: "CREATE TABLE media_events (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"                                                                                                                                                                               
   - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'media_events' already exists. Failing Query: "CREATE TABLE media_events (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255), start_date DATE, end_date DATE, website VARCHAR(255), location TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB"  
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company_type'. Failing Query: "ALTER TABLE bio ADD company_type VARCHAR(255)"                                                                                                                                                                     
   - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'company'. Failing Query: "ALTER TABLE bio ADD company VARCHAR(255)"             

Mostly this is confusing because it is reporting the same error multiple times. I have deleted the /tmp/doctrine_schema_[random_number].yml files and tried again, no luck. I also brought up the mysql console and manually deleted the tables and columns it is complaining about but it still generated the same error.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanfu3390 2011-05-13 18:06
    关注

    When things get messed up with migrations, there are a couple of things you might have to do to get back on track, depending on the situation.

    If you have a migration class that PARTLY works (going up or down in version) but has errors, then your database's schema is inconsistent between the migration, and it might then fail to go up or down. Then the next time you try to run it you get even more errors because of changes already committed.

    You then have to either apply ONLY the missing changes and re-run it until it succeeds. I do that by temporarily commenting out the parts of the migration that have already worked and correcting the problems with those that failed. It can also be done manually via your database's management tools but you run the risk of not exactly configuring things the same way.

    Sometimes it's also useful to manually change the value stored in the migration_version table (using a non-Doctrine database tool) to force Doctrine to realize it's at a different version. Then try migrating down and up again.

    Also, I highly recommend always testing new migration classes by applying them up, then back down one version and up again. There are bugs in the doctrine:generate-migrations-diff task that especially with foreign keys can create irreversible migrations. I find those need to be hand-edited before running them to be valid in both directions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)