2014-09-10 3 views
-1

많은 시간을 보냈지 만 외래 키로 마이그레이션을 계속 수행하지 못합니다. 나는외래 키로 Laravel 마이그레이션 1064 오류

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

} 

처럼 내 이전에 무엇이 잘못되었는지를 마이그레이션 할 어떤 클래스를 얻을?

답변

0

오류가이 모든 것을 말합니다.

$table->foreign('author')->references('id')->on('users')->onDelete(); 

이되고 :

$table->foreign('author')->references('id')->on('users')->onDelete('cascade'); 

아니면 단순히 :

$table->foreign('author')->references('id')->on('users'); 

가 문서화 here를 참조

은 아마 당신이 원했다.

+0

예. 오자 오류. 이 바보 같은 오류에 대해 대단히 죄송합니다. – fefe