mysql - Laravel 表拒绝在迁移表上注册并回滚或迁移

标签 mysql laravel

我有一个迁移表拒绝在迁移表中注册..

2014_10_12_000000_create_users_table    1
2014_10_12_100000_create_password_resets_table  1
2016_03_21_010421_create_orders_table   1
2016_03_21_010549_create_types_table    1
2016_03_21_010722_create_materials_table    1
2016_03_21_010814_create_ratings_table  1
2016_03_21_011205_create_costs_table    1
2016_03_21_012114_create_locations_table    1
2016_06_02_181122_create_assignments_table  1
2016_06_25_001455_create_bills_table    1
2016_07_26_195012_create_roles_table    1
2016_08_06_205440_create_permissions_table  1
2016_08_11_013917_create_material_order_table   1

文件:2017_03_04_201351_create_permission_role_table.php

<?php

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

class CreatePermissionRoleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        Schema::create('permission_role', function (Blueprint $table) {
            $table->integer('permission_id')->unsigned()->index();
            $table->integer('role_id')->unsigned()->index();

            $table->foreign('permission_id')
                ->references('id')
                ->on('permissions')
                ->onDelete('cascade');

            $table->foreign('role_id')
                ->references('id')
                ->on('roles')
                ->onDelete('cascade');

            $table->primary(['permission_id', 'role_id']);
        });
    }

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

这是迁移..

我尝试了composer dump它也没有出现..

它拒绝迁移..

我手动删除,但在回滚migrate:refreshmigrate时出现相同的错误。

最后就是错误:

  [Illuminate\Database\QueryException]
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'permission_role' already exists (SQL: create table `permission_role` (`permission_id` in
  t unsigned not null, `role_id` int unsigned not null) default character set utf8 collate utf8_unicode_ci)

  [PDOException]
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'permission_role' already exists

表信息:innoDB .

github 存储库:链接

https://github.com/lifesound/fixgate

最佳答案

您已经拥有表permission_role,现在您的迁移表与您的数据库不对齐。

如果您知道该怎么做,您可以手动编辑迁移表,恢复您丢弃的文件并运行“composer dump-autoload”,然后进行迁移

可能最好的方法是手动删除所有表(包括迁移表)并重新运行迁移。如果您可以删除所有表格。

关于mysql - Laravel 表拒绝在迁移表上注册并回滚或迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42602746/

相关文章:

php - 如何使用 View 在 php 中回显当前 Laravel 版本的版本?

php - Laravel 以编程方式获取特定页面

MySQL - 比较两个表的值并记录它们

mysql - 从 MySQL 导入和导出 filemaker

php - 数据库中的匹配名称

javascript - 在 Laravel View 中触发 jquery 事件

php - gRPC 在终端中工作但不在 laravel 项目中

mysql - 在 where 子句中使用两组条件

mysql - 如何为两个表制作一个共同的自增id

php - 当数字被零除时,Try catch 在 Laravel 5.6 中不起作用