我的tags表
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->timestamps();
});
}
我的article_tag表
public function up()
{
Schema::create('article_tag', function (Blueprint $table) {
$table->increments('id');
$table->integer('article_id')->unsigned()->index();
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
$table->integer('tag_id')->unsigned()->index();
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
$table->timestamps();
});
}
我的articles表
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 100);
$table->text('content');
$table->timestamps();
});
}
执行php artisan migrate
Migration table created successfully.
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table `laraveltest`.`#sql-111c_37` (errno: 150 "Foreign key cons
train
t is incorrectly formed") (SQL: alter table `article_tag` add constraint article_tag_article_id_foreign foreign ke
y (`a
rticle_id`) references `articles` (`id`) on delete cascade)
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table `laraveltest`.`#sql-111c_37` (errno: 150 "Foreign key cons
train
t is incorrectly formed")