【发布时间】:2016-03-23 16:24:54
【问题描述】:
即使在声明 SET FOREIGN KEYS CHECKS 之后,我也无法将我的 id 列的类型更改为整数。我收到错误
[照亮\数据库\查询异常]
SQLSTATE [HY000]:一般错误:1025 重命名错误 './abc/#sql-45d_6d' 到 './abc/oauth_clients' (errno: 150) (SQL: ALTER TABLE o auth_clients 更改 id id int(10) AUTO_INCREMENT)
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddAppIdToOauthClients extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
/**
Schema::table('oauth_clients', function(Blueprint $table)
{
$table->string('app_id',100);
});
*/
DB::statement('SET FOREIGN_KEY_CHECKS = 0;');
DB::statement('ALTER TABLE oauth_clients CHANGE id id int(10) AUTO_INCREMENT');
DB::statement('SET FOREIGN_KEY_CHECKS = 1;');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
/**
Schema::table('oauth_clients', function(Blueprint $table)
{
$table->dropColumn('app_id');
});
*/
DB::statement('SET FOREIGN_KEY_CHECKS = 0;');
DB::statement('ALTER TABLE oauth_clients CHANGE id id varchat(55);');
DB::statement('SET FOREIGN_KEY_CHECKS = 1;');
}
1,1 Top
更新: 这是我的 INNODB STATUS 上显示的错误
------------ 最新的外键错误 ------------------------ 151217 17:37:37 表 abc/oauth_client_endpoints 的外键约束出错:没有索引 将包含列作为第一列的引用表, 或引用表中的数据类型与表中的数据类型不匹配 桌子。约束: , 约束 “oauth_client_endpoints_client_id_foreign”外键(“client_id”) 参考 "oauth_clients" ("id") ON DELETE CASCADE ON UPDATE CASCADE 表中外键的索引是 “oauth_client_endpoints_client_id_redirect_uri_unique”见 http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html 正确的外键定义。
【问题讨论】: