我在Doctrine 2/ Sf2中更新了我的数据库模式,并在数据库中添加了一些新表。一切都进行得很顺利,但是当我想创建应用程序的管理端时,我意识到我需要一些ID才能成为AUTO_INCREMENT。
然后,我想改变我的模式。从这里。
X\XBundle\Entity\Currency:
type: entity
table: currencies
repositoryClass: CurrencyRepository
id:
id:
type: integer
fields:
name:
type: string
length: 255
slug:
type: string
length: 64
manyToMany:
brokers:
targetEntity: X\XBundle\Entity\Broker
mappedBy: currencies对此:
X\XBundle\Entity\Currency:
type: entity
table: currencies
repositoryClass: CurrencyRepository
id:
id:
type: integer
generator: { strategy: AUTO } # I changed on this row!
fields:
name:
type: string
length: 255
slug:
type: string
length: 64
manyToMany:
brokers:
targetEntity: X\XBundle\Entity\Broker
mappedBy: currencies然后,我尝试在CLI中运行php app/console doctrine:schema:update --force,并得到了以下消息:
SQLSTATE[HY000]: General error: 1833 Cannot change column 'id': used in a foreign key constraint 'FK_706E39538248176' of table 'forexcbc.broker_currencies'我现在什么都试过了。我手动删除外键并重新运行脚本,没有工作。我删除了这两张桌子之间的关系,没有用。有趣的是,桌子上什么都没有。
我的代理模式看起来像这样(我不知道这在任何形式上都有帮助)
X\XBundle\Entity\Broker:
type: entity
table: brokers
repositoryClass: BrokerRepository
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
slug:
type: string
length: 64
oneToMany:
accountTypes:
targetEntity: X\XBundle\Entity\AccountType
mappedBy: broker
cascade: ["persist"]
manyToMany:
currencies:
targetEntity: X\XBundle\Entity\Currency
inversedBy: brokers
joinTable:
name: broker_currencies
joinColumns:
broker_id:
referencedColumnName: id
inverseJoinColumns:
currency_id:
referencedColumnName: id我的问题是,在创建表之后,如何能够将ID字段设置为自动增量。再说一遍,桌子上什么都没有。
谢谢你提前提供帮助!
亚当
发布于 2014-08-23 09:03:46
与将更新应用于数据库不同,您可以转储要应用的SQL:
app/console doctrine:schema:update --dump-sql --complete打开mysql shell,选择DB并首先禁用外键检查:
SET FOREIGN_KEY_CHECKS = 0;然后在shell中执行生成的SQL查询。
完成后,关闭shell,然后再次运行doctrine:schema:update命令,以查看一切是否成功。
https://stackoverflow.com/questions/25459439
复制相似问题