1.1Symfony模型(Doctrine)之基础(Basic)

配置数据库

//推荐PostgreSQL
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"

生成数据库

php bin/console doctrine:database:create

创建实体

php bin/console make:entity

实体与表名称

Product实体
product表

创建字段

//同创建表
php bin/console make:entity

列类型

Main types
  * string
  * text
  * boolean
  * integer (or smallint, bigint)
  * float

Relationships / Associations
  * relation (a wizard 🧙 will help you build the relation)
  * ManyToOne
  * OneToMany
  * ManyToMany
  * OneToOne

Array/Object Types
  * array (or simple_array)
  * json
  * object
  * binary
  * blob

Date/Time Types
  * datetime (or datetime_immutable)
  * datetimetz (or datetimetz_immutable)
  * date (or date_immutable)
  * time (or time_immutable)
  * dateinterval

Other Types
  * ascii_string
  * decimal
  * guid
  * json_array

生成迁移文件

php bin/console make:migration

执行迁移文件

php bin/console doctrine:migrations:migrate

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/symfony/6710.html

发表评论

登录后才能评论