Symfony+Doctrine: Correct YAML syntax for default value of boolean field(Symfony+Doctrine:为布尔字段的默认值正确的 YAML 语法)
问题描述
我正在为我的 Symfony 应用程序处理架构,我需要将两个布尔字段的默认值设置为 false.但是,通过我尝试的所有方法,当生成 sql 时,它带有 default 关键字,但后面没有默认值.
I am working on the schema for my Symfony app, and I need to set the default value of two boolean fields to false. However, with all the ways I've tried to do it, when the sql gets generated, it comes out with the default keyword, but no default value after it.
我最后一次尝试是:
negotiable:
type: bool
default: "false"
complete:
type: bool
default: "false"
但我也尝试过 default: false, default: 'false', default: 0 因为 false 只是 0 的别名在 MySQL 中,default: '0'
but I have also tried default: false, default: 'false', default: 0 since false is just an alias for 0 in MySQL, and default: '0'
查询失败:
CREATE TABLE dormcode_project (id BIGINT AUTO_INCREMENT, client_id BIGINT, title VARCHAR(255), briefdesc LONGTEXT, spec LONGTEXT, coder_id BIGINT, paytype VARCHAR(30), negotiable bool DEFAULT , complete bool DEFAULT , created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX coder_id_idx (coder_id), INDEX client_id_idx (client_id), PRIMARY KEY(id)) ENGINE = INNODB
注意 negotiable bool DEFAULT , complete bool DEFAULT ,
我一直在使用的文件是 /config/doctrine/schema.yml 文件.我对 symfony/doctrine 有点陌生.我认为这是正确的,但我想我可能是错的.我在每次尝试插入 sql 之间执行 symfony cc 以确保它没有缓存架构.但它几乎似乎没有使用我一直在更改的文件......
The file I've been playing with is the /config/doctrine/schema.yml file. I'm kind of new to symfony/doctrine. I think this is the right one, but I guess I could be wrong. I do symfony cc between each attempt to insert the sql to make sure that it didn't cache the schema. But it almost seems like its not using the file I've been changing...
推荐答案
Boolean 是 TINYINT 的同义词.请改用 integer(1) 并将默认值设置为 0/1.
Boolean is a synonym for TINYINT. Use integer(1) instead and set your default to 0/1.
来源:
http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html
http://www.symfony-project.org/学说/1_2/en/04-Schema-Files
这篇关于Symfony+Doctrine:为布尔字段的默认值正确的 YAML 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony+Doctrine:为布尔字段的默认值正确的 YAML 语法
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
