在Rails4中10之后自动增量不起作用

时间:2015-03-11 14:49:46

标签: ruby-on-rails ruby-on-rails-4

我已在我的模型中编写了此代码,以便为我的模型model.rb中的每一行创建自动增加notice_no列

但是它增加了1到10个数字,之后它不是增量而不是打印为increments automatically till 10

after 10 it is not increment instead of that printing number 10 only

1 个答案:

答案 0 :(得分:1)

您的notice_no字段为varchar(即字符串)(不是integer类型)。只需在迁移文件中更改为integer并重建/迁移数据库。

mysql> show columns from test_num;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| num   | varchar(255) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> select * from test_num;
+------+
| num  |
+------+
| 8    |
| 9    |
| 10   |
+------+
3 rows in set (0.00 sec)

mysql> select max(num) from test_num;
+----------+
| max(num) |
+----------+
| 9        |
+----------+
1 row in set (0.00 sec)