“SQLSTATE[42S02]: Base table 或未找到视图” 运行 迁移时
" SQLSTATE[42S02]: Base table or view not found" when running migration
我目前正在学习使用 Laravel 开发 CMS 的课程。我对我的页面做了一些更改,因为我想给它们一个 "position" 特性来改变顺序。我以为我可以删除 tables,然后删除 运行 "php artisan migrate",然后再次播种 table。现在我总是收到以下错误消息:
C:\xampp\htdocs\siggen-cms>php artisan migrate
In Connection.php line 664:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'siggen-cms.pages' doesn't exist (SQL: select * from `pages`)
In Connection.php line 326:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'siggen-cms.pages' doesn't exist
有没有人解决这个问题。 Whosebug 上的所有类似问题都没有帮助。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->string('url')->unique();
$table->text('content');
$table->integer('position')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pages');
}
}
几个可能导致此问题的潜在问题:
- 如果您要删除所有内容并重新开始新的迁移,请检查迁移的位置(基于时间/日期)以确保 table 在 [之后] =24=]
pages
table 被创建。
更有可能是基于你所说的 "I thought that I can just delete the tables and then run "php artisan migrate”,你实际上并没有创建 table 因为你的迁移不会为此特定激活table.IE迁移已经运行页面文件,根据数据库迁移table,所以这个迁移文件不会被触及。
一个。要解决此问题,您可以删除整个数据库并从头开始,您可以尝试回滚迁移,或者为了快速修复,删除迁移 table 中此迁移文件所在的行。 IE SELECT * FROM migrations
,找到页面文件迁移所在行的 id
,然后删除该行。然后,下次你 运行 php artisan migrate
,它会创建 table.
谢谢大家的帮助。
我仍然不知道错误的原因,但我修复了它。
我只需要注释掉 "RouteServiceProvider" 中的所有方法。
任何人都知道为什么这会崩溃 Laravel?
我目前正在学习使用 Laravel 开发 CMS 的课程。我对我的页面做了一些更改,因为我想给它们一个 "position" 特性来改变顺序。我以为我可以删除 tables,然后删除 运行 "php artisan migrate",然后再次播种 table。现在我总是收到以下错误消息:
C:\xampp\htdocs\siggen-cms>php artisan migrate
In Connection.php line 664:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'siggen-cms.pages' doesn't exist (SQL: select * from `pages`)
In Connection.php line 326:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'siggen-cms.pages' doesn't exist
有没有人解决这个问题。 Whosebug 上的所有类似问题都没有帮助。
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->string('url')->unique();
$table->text('content');
$table->integer('position')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pages');
}
}
几个可能导致此问题的潜在问题:
- 如果您要删除所有内容并重新开始新的迁移,请检查迁移的位置(基于时间/日期)以确保 table 在 [之后] =24=]
pages
table 被创建。 更有可能是基于你所说的 "I thought that I can just delete the tables and then run "php artisan migrate”,你实际上并没有创建 table 因为你的迁移不会为此特定激活table.IE迁移已经运行页面文件,根据数据库迁移table,所以这个迁移文件不会被触及。
一个。要解决此问题,您可以删除整个数据库并从头开始,您可以尝试回滚迁移,或者为了快速修复,删除迁移 table 中此迁移文件所在的行。 IE
SELECT * FROM migrations
,找到页面文件迁移所在行的id
,然后删除该行。然后,下次你 运行php artisan migrate
,它会创建 table.
谢谢大家的帮助。 我仍然不知道错误的原因,但我修复了它。 我只需要注释掉 "RouteServiceProvider" 中的所有方法。 任何人都知道为什么这会崩溃 Laravel?