【问题标题】:SQLSTATE[42S02]: Base table or view not found: 1146 Table 'softwareproject.o_r_f_o_l_s' doesn't exist error in laravelSQLSTATE [42S02]:未找到基表或视图:1146 表 'softwareproject.o_r_f_o_l_s' 在 laravel 中不存在错误
【发布时间】:2019-02-12 04:24:35
【问题描述】:

如何解决这个问题?

错误:

SQLSTATE[42S02]:未找到基表或视图:1146 表 'softwareproject.o_r_f_o_l_s' 不存在(SQL:插入到 `o_r_f_o_l_s`(`region`、`user_id`、`updated_at`、`created_at` ) 值 (4165dsF, 3, 2018-09-06 20:33:58, 2018-09-06 20:33:58))

我的迁移:

<?php

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

    class CreateORFOLsTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('o_r_f_o_ls', function (Blueprint $table) {
                $table->increments('ORFOLId');
                $table->string('region');

                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->references('userId')->on('all_users');

                $table->timestamps();

            });
        }

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

【问题讨论】:

  • 这真的是表的名称,还是您为您的问题缩写了它? MySQL 中的表名有 64 个字符的限制。
  • 您确定错误来自此迁移吗?错误在于插入,但此迁移没有任何插入。

标签: mysql laravel migration


【解决方案1】:

粗心的错误..

according to the model, table name should change as o_r_f_o_l_s.`

错误是表名。 我想这对一些用户解决这个问题很有帮助。

【讨论】:

  • 你到底为什么要为这样的表命名?
  • 根据错误 o_r_f_o_l_s 表不退出。所以更改表名。当我们尝试 php artisan make:model ORFOLs -m 命令时,会自动创建模型和迁移。有时编辑迁移可能会发生这种粗心的错误。
  • @Devon 我猜这个疯狂的表名是那个疯狂的全大写模型名称的"snake case" plural name。就我个人而言,我会尽量坚持 Laravel 的模型名称约定(即单个大写字母),这样的名称可能会出现其他微妙的问题。
猜你喜欢
  • 1970-01-01
  • 2020-06-26
  • 1970-01-01
  • 2018-03-16
  • 2016-01-19
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 2021-12-22
相关资源
最近更新 更多