开发者

Rails 3 app - problem with saving integer to column with data type int(11)

I have following a structure of MySQL table:

+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Nu开发者_StackOverflowll | 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    |                |
+------------+----------+------+-----+---------+----------------+

And with this way I am saving data to my database:

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

And my problem is - I don't know how it is possible, but this query does not save the number to column "reg". I am getting this error

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')

I worked a lot with PHP and MySQL database, but this error I never got...

Where's the problem?


if you look at your schema, it says the default for :reg is NULL, and that it can not be NULL -- that might cause the problem you see

can you change the schema to allow :reg to be NULL and try again?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜