1

这是我的迁移,我正在使用 mysql,当我运行迁移时,它成功并且我查看了我的 mysql DB,表的名称是我想要的“receivedDocument”。

class CreateReceivedDocumentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('received_documents', function (Blueprint $table) {
            $table->id();
            $table->dateTime('receivedDate')->nullable();
            $table->string('subjectDescription')->nullable();
            $table->string('fromEntity')->nullable();
            $table->string('documentNumber')->nullable();
            $table->integer('documentTypeId')->nullable();
            $table->dateTime('documentDate')->nullable();
            $table->integer('responseTypeId')->nullable();
            $table->text('remarks')->nullable();
            $table->timestamps();
        });

        Schema::rename('received_documents', 'receivedDocument');
    }

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

当我使用 tinker 创建和保存记录时,它失败了。Tinker 似乎不知道我在迁移中更改了表名。

>>> $rd = new \App\ReceivedDocument();
=> App\ReceivedDocument {#3036}
>>> $rd->subjectDescription = 'description sample';
=> "description sample"
>>> $rd->documentNumber = '1234/2020';
=> "1234/2020"
>>> $rd->save();
Illuminate/Database/QueryException with message 'SQLSTATE[42S02]: Base table or
view not found: 1146 Table 'dossier.received_documents' doesn't exist (SQL: inse
rt into `received_documents` (`subjectDescription`, `documentNumber`, `updated_a
t`, `created_at`) values (description sample, 1234/2020, 2020-06-11 10:18:00, 20
20-06-11 10:18:00))'

如何告诉 tinker 我在迁移过程中发生了什么变化?

4

1 回答 1

0

在您的模型中,定义表如下:

protected $table = 'receivedDocument';
于 2020-06-11T10:44:03.050 回答