“General error: 1005 Can't create table” Using Laravel Schema Build and Foreign Keys

后端 未结 11 1120
予麋鹿
予麋鹿 2020-12-03 07:02

Essentially, I am having the same issue as this guy, minus the table prefix. Because I have no table prefix, his fix does not work. http://forums.laravel.com/viewtopic.php?i

11条回答
  •  一生所求
    2020-12-03 07:15

    You have to give the integer an unsigned flag in Laravel 5.4, like this:

    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('post_id');
            $table->text('title');
            $table->text('text');
            $table->integer('employee_post_id_number')->unsigned();
            $table->foreign('employee_post_id_number')->references 
            ('employee_id_number')->on('employees');
            $table->timestamps();
        });
    }
    

提交回复
热议问题