【发布时间】:2014-11-03 17:04:58
【问题描述】:
我已经花了很多时间,但仍然无法使用外键更改进行迁移。我明白了
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your S
QL syntax; check the manual that corresponds to your MySQL server version for the r
ight syntax to use near '1' at line 1 (SQL: alter table `posts` add constraint post
s_author_foreign foreign key (`author`) references `users` (`id`) on delete 1)
我尝试迁移的类看起来像
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
if (!Schema::hasTable('posts')) {
Schema::create('posts', function($table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('title', 255);
$table->string('slug', 255);
$table->unique('slug');
$table->string('type', 255);
$table->text('content');
$table->integer('parent');
$table->integer('author')->unsigned();
$table->string('avatar', 255);
$table->string('guid', 255);
$table->string('mime_type', 255);
$table->integer('menu_order');
$table->boolean('status');
$table->index('id');
$table->timestamps();
});
Schema::table('posts', function($table) {
$table->foreign('author')->references('id')->on('users')->onDelete();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::drop('posts');
}
}
我的迁移出了什么问题?
【问题讨论】:
标签: mysql laravel-4 syntax-error database-migration