我正在试图挽救一个糟糕的Gitorious装置。我使用mysqldump
转储了SQL表,但现在我遇到了新版本的Gitorious在几个地方改变了它的SQL模式的问题。
特别是,旧版本有一个表taggings
,看起来像
mysql> describe taggings;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tag_id | int(11) | YES | MUL | NULL | |
| taggable_id | int(11) | YES | MUL | NULL | |
| taggable_type | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
在新版本中,此表增加了三列:
mysql> describe taggings;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tag_id | int(11) | YES | MUL | NULL | |
| taggable_id | int(11) | YES | MUL | NULL | |
| taggable_type | varchar(255) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| tagger_id | int(11) | YES | | NULL | |
| tagger_type | varchar(255) | YES | | NULL | |
| context | varchar(255) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
这样
grep 'INSERT INTO `taggings`' inuse.sql | mysql -uroot gitorious_production
失败
ERROR 1136 (21S01) at line 1: Column count doesn't match value count at row 1
有没有一种简单的方法可以告诉MySQL最后两个字段应该保留为默认值NULL
?
(新的Gitorious'taggings
表开始是空的。)
答案 0 :(得分:1)
作为一般的最佳做法,您应该提及您要插入的字段名称:
Insert into taggings (id,tag_id,taggable_id,taggable_type,created_at) values (...your values...)
答案 1 :(得分:0)
将新表格标记重命名为taggings_old
使用旧架构创建一个名为taggings的表
插入数据
将新列添加到表格标记