2017-03-12 76 views
2

我創建遷移成功,但不能查看數據庫中的表,當我去「PHP工匠遷移」我面臨着一個錯誤說:基表或視圖未找到:1146

基表或視圖不發現:1146 pakishops.advertisement不存在。

這裏是遷移代碼:

<?php 

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

class CreateAdvertisementTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::table('advertisement', function (Blueprint $table) { 
       $table->increments('id'); 

       $table->integer('shop_id')->unsigned(); 
       $table->foreign('shop_id') 
       ->references('id') 
       ->on('shops') 
       ->onDelete('cascade'); 

       $table->string('image')->default('default.jpg'); 
       $table->datetime('starting_date'); 
       $table->datetime('ending_date'); 
       $table->boolean('is_paid'); 
       $table->boolean('is_active'); 

       $table->timestamps(); 
     }); 
    } 

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

我應該怎麼做來解決這個問題?

回答

2

更改table()方法:

Schema::table 

create()

Schema::create 

table()方法改變現有的表。 create()創建新表。

https://laravel.com/docs/5.4/migrations#migration-structure

+1

感謝阿列克謝Mezenin你是真正有用的 –

+0

@AsifNawaz如果這回答了你的問題,請你將其標記爲正確的:) –

+0

@AsifNawaz請接受的答案... –

0

問題在代碼:

要創建表遷移文件應該有create()法代替的Schematable()方法。

它是怎麼發生的?

你必須叫

php artisan make:migration add_votes_to_users_table --table=users 

相反,你只需要調用

php artisan make:migration create_users_table --create=users 

table方法可用於更改表和create方法用於創建表。

樂於幫助:) :) :)

相關問題