这是我的迁移文件
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->text('payload');
$table->integer('last_activity');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('sessions');
}
}
它是在我跑的时候创建的
php artisan session:table
数据库连接已正确配置,因为项目正在写入和读取它没有问题。
从我运行的项目的根目录
php artisan migrate
我收到以下错误消息
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'sessions' already exists (SQL: create table `sessions` (`id` varchar(255) not null, `payload` text not null, `last_activity` int not null) default character set utf8 collate utf8_unicode_ci)
[PDOException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'sessions' already exists
我知道我应该跑
composer dump-autoload
但我已经尝试过,有没有它,我得到了相同的结果。我还在$ table参数之前尝试了Blueprint类型。
它的行为就像访问某个不同的数据库,而不是它在运行项目时使用的数据库
如果尚未在其中添加数据,请删除迁移。或者做php artisan migrate:rollback.Then php artisan config:clear然后重启你的服务器。然后重新运行迁移