【问题标题】:Base table or view not found: 1146 Table 'epharmacy.medicines' doesn't exist未找到基表或视图:1146 表“epharmacy.medicines”不存在
【发布时间】:2017-07-22 13:45:54
【问题描述】:

我正在尝试构建一个表,但是当我运行此命令“php artisan migrate”时出现此错误:

[照亮\数据库\查询异常]
SQLSTATE [42S02]:未找到基表或视图:1146 表 'epharmacy.medici
nes' 不存在 (SQL: alter table medicines add id int unsigned not
null auto_increment 主键,加namevarchar(255) 不为空,加typ
e
varchar(255) 不为空,加potencyvarchar(255) 不为空,加created
_at
timestamp null,加updated_attimestamp空)

迁移:

<?php

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

class CreateMedicineTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('medicines', function (Blueprint $table) {
            $table->increments('id');
            $table->String('name');
            $table->String('type');
            $table->String('potency');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('medicines', function (Blueprint $table) {
            //
        });
    }
}

【问题讨论】:

  • 将类名 createmedicinetable 更改为 criatemedicines 表并尝试

标签: php laravel-5.3


【解决方案1】:

根据the docs,应该是:

<?php

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

class CreateMedicineTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('medicines', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('type');
            $table->string('potency');
            $table->timestamps();
        });
    }

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

}

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 1970-01-01
    • 2018-05-31
    • 2020-07-20
    • 2018-10-17
    • 1970-01-01
    • 2014-10-08
    • 2019-01-28
    • 2017-08-02
    相关资源
    最近更新 更多