【问题标题】:Laravel, why can't I run a successful create table migration with a slightly different spelling of table name?Laravel,为什么我不能使用稍微不同的表名拼写成功地运行创建表迁移?
【发布时间】:2014-07-13 21:01:46
【问题描述】:

我正在尝试在 Laravel 4 中运行迁移,但我不断收到以下错误:

 [Illuminate\Database\QueryException]  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ramen.categories  ' doesn't exist (SQL: create table `categories` (`id` int unsigned not null  auto_increment primary key) default character set utf8 collate utf8_unicode_ci)

奇怪的是,如果我将表名从“categories”更改为“categoriez”,迁移就会成功运行。

这是我用来创建迁移的命令:

php artisan migrate:make create_categories_table --table=categories --create=categories

这是实际的迁移文件:



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

class CreateCategoriesTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('categories', function(Blueprint $table)
    {
        $table->increments('id');
        $table->timestamps();

        $table->integer('parent')->unsigned();
        $table->string('category_type');
        $table->string('name');
        $table->string('type');

        $table->index('type');
        $table->index('parent');
        $table->index('name');
    });
}

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

}

同样,如果我运行此迁移,我会收到错误消息,但如果我只是将“类别”更改为“类别”,则迁移会成功运行。

我之前设置了一个类别表,但我没有通过迁移设置该表。我已经放下了这张桌子。我还有一个已删除的类别模型文件。我已删除所有数据库表并重新运行所有迁移并尝试运行composer dump-autoload(尽管我不确定这与此问题有什么关系)。

为什么我在尝试创建类别表时会收到此“未找到表”错误?

我已经检查了这个与我的问题类似但没有帮助我解决这个错误的线程:Laravel 4 migrate base table not found

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    原来这是 MYSQL 的问题,而不是 Laravel。我尝试直接在 PHP MyAdmin 中创建“类别”表,但无法这样做。

    创建一个任意命名的表,将该表重命名为“类别”,然后删除该表,似乎可以解决问题。之后,我能够成功运行迁移。

    https://stackoverflow.com/a/10925588/1043556

    【讨论】:

      猜你喜欢
      • 2018-09-29
      • 1970-01-01
      • 2020-08-01
      • 2016-12-16
      • 2017-10-08
      • 2015-03-28
      • 2016-07-04
      • 2020-11-10
      • 2021-06-29
      相关资源
      最近更新 更多