未找到基表或视图:1146

时间:2017-03-12 14:45:45

标签: laravel

我成功创建了迁移,但是当我选择" PHP artisan migrate"时,我无法在数据库中看到表格。我正面临一个错误:

找不到基表或视图: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 个答案:

答案 0 :(得分:2)

更改table()方法:

Schema::table

create()

Schema::create

table()方法更改现有表。 create()创建新表。

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

答案 1 :(得分:0)

代码中的问题:

要为迁移文件创建表格,应使用create()方法代替table() Schema方法。

怎么回事?

你必须要打电话

php artisan make:migration add_votes_to_users_table --table=users

相反,你只需要打电话

php artisan make:migration create_users_table --create=users

table方法可用于更改表,create方法用于创建表。

很乐意帮助:) :) :)