在MySQL中创建了一个名为“motor”的数据库后,我使用以下命令在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
也没有起作用。
你有什么想法,我可能做错了什么?
doctrine:build --sql
的输出。关于doctrine:build --all
,它没有给我任何错误。 - rfc1484schema.sql
已经填充了。你尝试过删除schema.sql
并重新启动build --sql
吗?另外,请检查文件/文件夹权限。 - j0k