2016-01-13 27 views
0

我用CreateNewsTable migratin創建了新聞表。在CreateNewsTable遷移代碼是:laravel migration生成的外鍵約束的名稱是什麼

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateNewsTable extends Migration 
{ 
/** 
* Run the migrations. 
* 
* @return void 
*/ 
public function up() 
{ 
    Schema::create('news', function (Blueprint $table) { 
     $table->string('author'); 
     $table->string('title'); 
     $table->string('title_image_path'); 
     $table->string('summary'); 
     $table->text('body'); 
     $table->bigInteger('timestamp'); 
     $table->boolean('published'); 

     $table->primary(['author', 'title', 'timestamp']); 
     $table->foreign('author')->references('id')->on('users'); 
    }); 
} 

/** 
* Reverse the migrations. 
* 
* @return void 
*/ 
public function down() 
{ 
    Schema::drop('news'); 
} 
} 

現在我想刪除外鍵約束,但我不知道外鍵約束的名字。 請提前幫助我,感謝您的回答。

回答

0

您可以找到INFORMATION_SCHEMA外鍵的表KEY_COLUMN_USAGE

例如,要查找外鍵的表news

SELECT * FROM information_schema.KEY_COLUMN_USAGE where TABLE_NAME = 'news';

外鍵的名稱是在列名爲CONSTRAINT_NAME

+0

Yottatron,謝謝你快速和有用的answer.my問題解決。 – loghman

+0

非常好,很高興聽到,很高興我可以幫助。 –