数据库、表创建(以PostgreSQL为例)

  1. 安装、运行、启动PostgreSQL
  2. 配置数据库
     database_host: 192.168.1.130
     database_port: 5432
     database_name: db_book
     database_user: postgres
     database_password: geng
    
  3. 配置app/config.yml
     naming_strategy: doctrine.orm.naming_strategy.underscore
    
  4. 创建数据库
     单数据库
     php bin/console doctrine:database:create
     多数据库
     php bin/console doctrine:database:create --em="default"
    
  5. 创建实体
     单数据库
     php bin/console doctrine:generate:entity
     多数据库
     php bin/console doctrine:generate:entity --em="default"
    
  6. 逐个填写字段属性(举例)

     New field name (press <return> to stop adding fields): assess_id
     Field type [integer]:
     Is nullable [false]:
     Unique [false]: true
    
     New field name (press <return> to stop adding fields): assess_start_time
     Field type [string]: datetime
     Is nullable [false]:
     Unique [false]:
    
     New field name (press <return> to stop adding fields): assess_end_time
     Field type [string]: datetime
     Is nullable [false]:
     Unique [false]:
     输入回车停止。
    
  7. 生成数据库表(该操作只能在dev环境执行)
     php bin/console doctrine:schema:update --force
    
  8. 上一步如果报错:"No Metadata Classes to process",检查app/config.yml
     doctrine:
         orm:
             default_entity_manager: default
             entity_managers:
                 default:
                     connection: default
                     mappings:
                         AppBundle: ~
                         #这里加上entity所在的Bumdle
                         我的Bundle: ~
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-07-08 16:49:59

results matching ""

    No results matching ""