doubeiji2602 2016-09-29 11:31
浏览 24

SQL错误多对多迁移文件Laravel 5

I'm trying to create a new pivot table in my application. I want to connect my users table to my customers table. It must be a many-to-many relationship. I have created a migration file. It looks like this:

<?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');
}
}

When i run php artisan migrate i get the following error message:

[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) 

In the users table the ID is an integer and in the customers table facebook_id is a string. In my opinion i'm doing it the right way, so I have no idea what i'm doing wrong?

Thanks in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行