从数据库表生成实体
1. 由数据库生成模型:
php bin/console doctrine:mapping:convert --from-database yml D:db
D: est_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"
(模型要改第一行路径,不然在实例表结构时会报错如下:)
Invalid mapping file 'AppBundle.Entity.AppUser.orm.yml' for class 'AppBundleEntityAppUser'.
example:
app_user表生成的模型第一行为:'AppUser:';要将此改为 “AppBundleEntityAppUser:”
->痞子鱼
2.实例所有表结构
表结构文件复制至:AppBundleResourcesconfigdoctrine
php bin/console doctrine:generate:entities AppBundle/Entity/ --path src/
实例单个表结构(SiteChannel)
php bin/console doctrine:generate:entities AppBundle/Entity/SiteChannel --path src/
D: est_backend>php bin/console doctrine:generate:entities AppBundle/Entity/AppUser --path src/ Generating entities for namespace "AppBundleEntityAppUser" > backing up AppUser.php to AppUser.php~ > generating AppBundleEntityAppUser
数据库迁移(symfony本地迁移到数据库):
开启数据库迁移:composer require doctrine/doctrine-migrations-bundle "^1.0"
实体更新到数据库
Resources->Entity
(比较)
php bin/console doctrine:migrations:diff
(迁移)
php bin/console doctrine:migrations:migrate
->痞子鱼