symfony 数据库表生成实体、迁移数据库

从数据库表生成实体

1. 由数据库生成模型:
  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"

  (模型要改第一行路径,不然在实例表结构时会报错如下:)

   Invalid mapping file 'AppBundle.Entity.AppUser.orm.yml' for class 'AppBundle\Entity\AppUser'.
example:
  app_user表生成的模型第一行为:'AppUser:';要将此改为 “AppBundle\Entity\AppUser:”
 ->痞子鱼
2.实例所有表结构
  表结构文件复制至:AppBundle\Resources\config\doctrine
  php bin/console doctrine:generate:entities AppBundle/Entity/ --path src/
  实例单个表结构(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
 数据库迁移(symfony本地迁移到数据库):
  开启数据库迁移:composer require doctrine/doctrine-migrations-bundle "^1.0"
  实体更新到数据库
  Resources->Entity
  (比较)
  php bin/console doctrine:migrations:diff
  (迁移)
  php bin/console doctrine:migrations:migrate
 
 ->痞子鱼
posted @ 2017-07-10 20:35  痞子鱼  阅读(1448)  评论(0编辑  收藏  举报