Symfony+Doctrine:布尔字段默认值的正确 YAML 语法
我正在为我的 Symfony 应用程序开发架构,我需要将两个布尔字段的默认值设置为 false。然而,通过我尝试过的所有方法,当生成 sql 时,它会带有 default 关键字,但后面没有默认值。
我的最后一次尝试是:
negotiable:
type: bool
default: "false"
complete:
type: bool
default: "false"
但我也尝试过 default: false
, default: 'false'
, default: 0
因为 false 只是一个别名对于 MySQL 中的 0,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 以确保它没有缓存架构。但它似乎没有使用我一直在更改的文件......
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.
my last attempt was:
negotiable:
type: bool
default: "false"
complete:
type: bool
default: "false"
but I have also tried default: false
, default: 'false'
, default: 0
since false is just an alias for 0 in MySQL, and default: '0'
Failing Query:
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
Notice negotiable bool DEFAULT , complete bool DEFAULT ,
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于我没有足够的积分来添加评论,因此我会将其添加为通过 Google 和像我这样找到此内容的人的答案。我知道这是一个老问题。
在 Symfony 2.5(至少)中,在 YAML 中设置默认值的正确方法如下:
Since I haven't enough points to add a comment, I'll add it as an answer for people finding this through Google and the sorts like myself. I know it's an old question.
In Symfony 2.5 (at least), the correct way of setting a default value in YAML is as follows:
布尔值是 TINYINT 的同义词。请改用
integer(1)
并将默认值设置为 0/1。资料来源:
http://dev.mysql.com/doc /refman/5.5/en/numeric-type-overview.html
http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files
Boolean is a synonym for TINYINT. Use
integer(1)
instead and set your default to 0/1.Sources:
http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html
http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files
您应该在模式中使用“boolean”,而不是使用“bool”。另外,默认值: false 应该可以工作。
Instead of using "bool" you should use "boolean" in schema. Also, default: false should work.