重构项目的时候在数据库中增加了一个字段,并要把该字段作为主键。由于原来已经存在主键值了,所以要在[.install]文件中打补丁。
db_drop_primary_key('question_analysis_stats_main_points_all');
db_add_primary_key('question_analysis_stats_main_points_all', array('pid', 'tid', 'cid','subject', 'weight', 'type'));
然后运行 run Updates,惊诧地出现了报错
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition;
there can be only one auto column and it must be defined as a key
既然db_drop_primary不行,就试着使用db_query()
db_query('ALTER TABLE question_analysis_stats_main_points_all DROP PRIMARY KEY ,ADD PRIMARY KEY (pid, tid, cid,subject, weight, type)');
成功了