我之前创建了USERS表.现在,我已经创建了一个新迁移,以便在我的模式中创建一个新的BOOKS表.当我try 运行该命令时

php artisan migrate

It shows:

[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre
ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr
ement primary key, `username` varchar(255) not null, `email` varchar(255) n
ot null, `password` varchar(255) not null, `created_at` timestamp default 0
 not null, `updated_at` timestamp default 0 not null) default character set
 utf8 collate utf8_unicode_ci)

Here is my new migration table:

<?php

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

class CreateBooksTable extends Migration {
    public function up()
    {
        Schema::create('books', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name');
            $table->string('auther');
            $table->string('area');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop('books');
    }
}

我怎样才能消除这个错误?

推荐答案

你需要跑

php artisan migrate:rollback

如果这也失败了,只需进入并删除所有表,您可能必须这样做,因为您的迁移表似乎混乱不堪,或者您的用户表在运行上一次回滚时没有删除该表.

编辑:

发生这种情况的原因是,您之前运行过回滚,但代码中出现了一些错误,或者没有删除表.然而,这仍然会弄乱laravel迁移表,就其而言,您现在没有向上推用户表的记录.然而,用户表确实存在,并且此错误被抛出.

Php相关问答推荐

调用woocommerce_customer_Save_add动作挂钩时发生致命错误

输入手写CSV时在PHP中进行日期判断

启用额外的WooCommerce产品库存位置

PHP,ZipArchive删除一个空文件?

在Google云存储对象上从PHP设置缓存控制TTL会更改错误的元数据

为什么本地主机(Xampp)上的laravel运行速度比普通html站点慢?

如何使用MS Graph PHP SDK V2下载文件

在个人资料页面上显示个人资料图像

execute_query 和prepare+execute 有什么区别?

对 WooCommerce 购物车和 checkout 中显示的运输方式进行排序

多个产品类别 Select 自定义 WooCommerce 插件设置页面

在 DateTime 或 DateTimeImmutable 对象上调用modify() 时是否必须使用空格?

在 vue 自定义渲染器中访问变量

PHP 简单 XML Xpath 上移树(带有名称的父级)

symfony/notifier + twig/inky-extra 在 dunglas/symfony-docker 中缺少 ext-xsl.

在WooCommerce中显示 checkout 的高级自定义字段(Advanced Custom Fields)并保存其值

遇到特定键时修改二维数组以创建嵌套数据集

php-http/discovery 插件 1.15.1 是否仍在使用自己的模块 destruct Contao 4.13 中的composer 安装?

即使密码匹配,密码处理程序也会返回错误

Laravel 从嵌套数组的第二级获取最后一项