php – 在Symfony中使用Doctrine创建表

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 在Symfony中使用Doctrine创建表脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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,没有在我的DB中生成任何表.但是它给出了一个成功的消息输出

>> doctrine  creating tables
>> doctrine  created tables successfully

命令$PHP symfony doctrine:build –all,也没用.

知道我可能做错了吗?

解决方法

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

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

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

脚本宝典总结

以上是脚本宝典为你收集整理的php – 在Symfony中使用Doctrine创建表全部内容,希望文章能够帮你解决php – 在Symfony中使用Doctrine创建表所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。