mysql - Rails 3 应用程序 - 将整数保存到数据类型为 int(11) 的列时出现问题

标签 mysql ruby-on-rails-3 integer

我有以下 MySQL 表的结构:

+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Null | Key | Default | Extra          |
+------------+----------+------+-----+---------+----------------+
| id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| reg        | int(11)  | NO   |     | NULL    |                |
| descr      | text     | YES  |     | NULL    |                |
| created_at | datetime | YES  |     | NULL    |                |
| updated_at | datetime | YES  |     | NULL    |                |
+------------+----------+------+-----+---------+----------------+

通过这种方式,我将数据保存到我的数据库中:

 @saving = Table.new(:reg => 1234, :descr => params[:descr]).save

我的问题是 - 我不知道这怎么可能,但是这个查询不会将数字保存到“reg”列。我收到这个错误

Mysql2::Error: Column 'reg' cannot be null: INSERT INTOname_of_table(updated_at,descr,reg,created_at) VALUES ('2011-06-06 20:40:43', 'description of man', NULL, '2011-06-06 20:40:43')

我经常使用 PHP 和 MySQL 数据库,但我从来没有遇到过这个错误...
问题出在哪里?

最佳答案

如果您查看您的架构,它表示 :reg 的默认值为 NULL,并且它不能为 NULL —— 这可能会导致您看到的问题

您能否更改模式以允许 :reg 为 NULL 并重试?

关于mysql - Rails 3 应用程序 - 将整数保存到数据类型为 int(11) 的列时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6257934/

相关文章:

ruby-on-rails-3 - Rails 3 中 View 中的记录分组?

r - 如何创建一个返回 2 个整数之和的函数?

php - 删除中间一行以及如何在mysql中刷新表id(自动递增)

mysql - LOAD DATA LOCAL INFILE 给出错误 The used command is not allowed with this MySQL version

ruby-on-rails - 不知道如何构建 rake db :migrate on Ubuntu natty?

powershell - 连接 String 和 Int 以形成文件名前缀

java - 在 Java 中,像 "int"这样的原始数据类型是一个类还是一个对象?

.net - MySql Connector/NET 将 Guids 映射到什么数据类型?

java - Java 和 SQL 中的时间跨度?

ruby-on-rails - Ruby:-查找文件中某个字符的出现次数