所以我正在尝试迁移此代码:
我有6次迁移,例如(或类似):
反应
class Reaction extends Migration
{
public function up()
{
Schema::create('reaction', function (Blueprint $table) {
$table->increments('reaction_id');
$table->integer('user_id');
$table->integer('event_id');
$table->integer('reaction_type');
$table->string('comment');
$table->timestamp('date');
});
}
public function down()
{
Schema::drop('reaction');
}
}
产品
class Products extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('product_id');
$table->string('name');
$table->integer('price');
$table->bigInteger('pieces');
$table->timestamp('date_added');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
但是当我输入php artisan migrate
错误:
vagrant@homestead:~/Code/Laravel$ php artisan migrate
Migrating: 2019_01_21_134236_users
Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`users_id` int unsigned not null auto_increment primary key, `last_name` varchar(255) not null, `first_name` varchar(255) not null, `email` varchar(255) not null, `password` varchar(255) not null, `statut` int not null, `date_added` timestamp not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at /home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
/home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
2 PDOStatement::execute()
/home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
Please use the argument -v to see more details.
有人可以帮助我吗?
答案 0 :(得分:1)
如果检查错误跟踪:
Illuminate \ Database \ QueryException:SQLSTATE [42S01]:基表或 视图已存在:1050表“用户”已存在(SQL:创建 表“用户” ...........
这意味着用户表已经存在,因此在您进行迁移时,它试图创建一个已经在数据库中创建的表。
注意:不要忘记先备份数据库
从数据库中删除用户表也会从迁移表中删除用户条目。
之后,要运行所有未完成的迁移,请执行migration Artisan命令:php artisan migrate