Creating tables using Doctrine in Symfony

After I created a β€œmotor” database in MySQL, I configured the database in Symfony with this command:

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

In appname/config/doctrine/ I have a schema.yml file.

In this file, I defined the following table:

 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 } 

Then I ran the command:

 $ php symfony doctrine:build --model 

Which gave me the following result:

 >> 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 

After that, I started generating sql with this command:

 $ php symfony doctrine:build --sql 

Output:

 >> 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 

However, in appname/data/sql/ generated schema.sql file schema.sql empty.

So, this $ php symfony doctrine:insert-sql command did not create any table in my database. However, he gave a successful message output:

 >> doctrine creating tables >> doctrine created tables successfully 

The $ php symfony doctrine:build --all does not work either.

Any idea what I can do wrong?

+4
source share
1 answer

It seems that there was nothing wrong with the methodology I used for this.

The problem arose in the version of Symfony that I used, which for some reason did not work correctly.

To fix this, I downloaded the latest version of Symfony 1.4.18 and ran the code again, this time it worked correctly.

+1
source

Source: https://habr.com/ru/post/1435483/


All Articles