Home > Backend Development > PHP Tutorial > An explanation of how symfony generates database table entities and migrates databases

An explanation of how symfony generates database table entities and migrates databases

巴扎黑
Release: 2023-03-13 15:54:01
Original
2257 people have browsed it

After two days of contact, I found that symfony is really awesome. I was confused about which one is better, laravel or symfony. After learning laravel for a week, I found that there were too few documentation and learning materials. I immediately turned to symfony and discovered that it has the same functions as laravle. It’s almost the same, so I didn’t watch Laravle in vain the past week. But today I found a very good function, which is more similar to Java. I was happy for a while. Let me share with you how to automatically generate database table entities with just a few clicks like Java.

I use Symfony3.0, generates certain connection database configuration information for database entities. The connection configuration information is in the app/config/parameters.yml file. Symfony will automatically identify which database it is. If you want to study it carefully, check out the documentation! I was also drunk when talking about the document. I copied every sentence into Baidu Translate to understand the meaning.

Generate entities from database table


1. Generate model from database:
 php bin/console doctrine:mapping: convert --from-database yml D:\db\
D:\test_backend>php bin/console doctrine:mapping:convert --from-database yml D:\db\
Processing entity "AppUser"
Processing entity "Channel"
Processing entity "MigrationVersions"

Exporting "yml" mapping information to "D:\db"
Copy after login

 (The model needs to change the first line of path, otherwise the following error will be reported in the instance table structure:)

 Invalid mapping file 'AppBundle.Entity.AppUser.orm.yml' for class 'AppBundle\Entity\AppUser'.
example:
 Model generated by app_user table The first line: 'AppUser:'; To change this to "AppBundle\Entity\AppUser:"
->PIZIYU
2. All table structures of the instance
Copy the table structure file to: AppBundle\Resources\config\doctrine
php bin/console doctrine:generate:entities AppBundle/Entity/ --path src/
Instance single table structure (SiteChannel )
 php bin/console doctrine:generate:entities AppBundle/Entity/SiteChannel --path src/
D:\test_backend>php bin/console doctrine:generate:entities AppBundle/Entity/AppUser --path src/Generating entities for namespace "AppBundle\Entity\AppUser"
  > backing up AppUser.php to AppUser.php~
  > generating AppBundle\Entity\AppUser
Copy after login
Database migration (Symfony local migration to database):
Start database migration: composer require doctrine/doctrine-migrations-bundle "^1.0"
Entity update to database
Resources-> ;Entity
 (Compare)
 php bin/console doctrine:migrations:diff
 (Migration)
 php bin/console doctrine:migrations:migrate
->Ruffian Fish

The above is the detailed content of An explanation of how symfony generates database table entities and migrates databases. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template