我正在尝试在我的应用程序中创建一个新的数据透视表。我想将我的users表连接到customers表。它必须是多对多的关系。我创建了一个迁移文件。它看起来像这样:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersCustomersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_user', function (Blueprint $table) {
$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->string('customer_fb_id')->unsigned()->index();
$table->foreign('customer_fb_id')
->references('facebook_id')
->on('customers')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('customer_user');
}
}
当我运行php artisan migrate时,我收到以下错误消息:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near 'unsigned not null, `created_at` timestamp
default 0 not null, `updated_at` times' at line 1 (SQL: create table `customer_user`
(`user_id` int unsigned not null, `customer_fb_id` varchar(255) unsigned not null, `created_at`
timestamp default 0 not null, `updated_at` timestamp default 0 not null)
default character set utf8 collate utf8_unicode_ci)
在users表中,ID是一个整数,在customers表中,facebook_id是一个字符串。在我看来,我正在以正确的方式做到这一点,所以我不知道我做错了什么?
提前致谢!