Doctrine 2迁移如何使用sqlite db更改表?

时间:2010-09-04 15:05:30

标签: php sqlite doctrine migration doctrine-orm

我在更改doctrine 2的迁移中遇到了一些问题。以下代码总是抛出错误:平台不支持“Doctrine \ DBAL \ Platforms \ AbstractPlatform :: getAlterTableSQL”操作

这很奇怪,因为sqlite支持alter table。

public function up(Schema $schema)
{
    $user = $schema->getTable('user');
    $user->addColumn('resellerId', 'integer', array(
        'length'        => '10',
        'notnull'       => true,
        'unsigned'      => true,
    ));
}

2 个答案:

答案 0 :(得分:4)

即使Sqlite“支持”ALTER TABLE,与大多数其他数据库(http://www.sqlite.org/lang_altertable.html)相比,允许的操作集也是最小的,因此它被认为是Doctrine DBAL不支持的原因。

答案 1 :(得分:0)

在使用ORM时,我注意到MySQL和SQLite之间存在一些琐碎的差异。 使用Doctrine,我发现在SQLite中不像在MySQL中那样维护外键关系。

这是一个痛苦,因为我在内存dbs中使用SQLite进行单元测试,因为我无法保证在SQLite中传递的持久性测试也会传递到MySQL中。

实际上,为了让SQLite在内存dbs中与Doctrine一起工作,我不得不调整Doctrine SQLite驱动程序(http://thecodeabode.blogspot.com/2010/12/dropping-sqlite-in-memory-databases-in.html处的代码),因为为删除数据库而生成的sql语法在内存dbs中失败。