2017-03-12 44 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方法用于创建表。

乐于帮助:) :) :)

相关问题