在Symfony中使用Doctrine创建表

时间:2012-09-21 11:21:47

标签: php symfony1 doctrine symfony-1.4 doctrine-1.2

在MySQL中创建了“motor”DB后,我使用以下命令在Symfony中配置了数据库:

$ php symfony configure:database "mysql:host=localhost;dbname=motor" root <mypassword>

appname/config/doctrine/下,我有schema.yml个文件。

在这个文件中我定义了下表:

Car:
  actAs: { Timestampable: ~ }
  columns: 
    brand: { type: string(255), notnull: true }
    model: { type: string(255), notnull: true }
    version: { type: string(255), notnull: true }
    url: { type: string(255), notnull: true }
    year: { type: string(4), notnull: true }
    info: { type: string(10000), notnull: true }
    updated_at: { type: timestamp, notnull: true }
    created_at: { type: timestamp, notnull: true } 

然后我执行了命令:

$ php symfony doctrine:build --model

这给了我以下输出:

>> doctrine  generating model classes
>> file+     /tmp/doctrine_schema_57936.yml
>> tokens    /home/username/webapps/www/appname/lib/model/doctrine/CarTable.class.php
>> tokens    /home/username/webapps/www/appname/lib/model/doctrine/Car.class.php
>> tokens    /home/username/webapps/www/appname/lib/model/doctrine/base/BaseCar.class.php
>> autoload  Resetting application autoloaders
>> file-     /home/username/webapps/www/appname/cache/frontend/dev/config/config_autoload.yml.php

之后我继续用这个命令生成sql:

$ php symfony doctrine:build --sql

输出结果为:

>> doctrine  generating model classes
>> file+     /tmp/doctrine_schema_89541.yml
>> tokens    /home/username/webapps/www/motor/lib/model/doctrine/base/BaseCar.class.php
>> autoload  Resetting application autoloaders
>> file-     /home/username/webapps/www/motor/cache/frontend/dev/config/config_autoload.yml.php
>> doctrine  generating sql for models
>> doctrine  Generated SQL successfully for models

但是,在appname/data/sql/下,生成的文件schema.sql为空。

所以这个命令$ php symfony doctrine:insert-sql没有在我的数据库中生成任何表。但它提供了成功的消息输出:

>> doctrine  creating tables
>> doctrine  created tables successfully

命令$ php symfony doctrine:build --all也没有用。

知道我可能做错了吗?

1 个答案:

答案 0 :(得分:1)

似乎我使用的方法没有任何问题。

问题出现在我使用的Symfony版本中,由于某种原因,该版本无法正常工作。

为了解决这个问题,我下载了最新的Symfony 1.4.18版本并再次运行代码,这次它运行正常。