首页 > 解决方案 > Laravel 8.55 php artisan 迁移行为后 php artisan schema:dump --prune

问题描述

我在我的开发环境中运行了 php artisan schema:dump --prune。

出现架构文件夹,并按预期清除迁移文件夹。

我创建了 2 个新迁移来创建 2 个新表,但是当我运行 php artisan migrate 时,它​​会尝试运行旧迁移。

自尝试以来,我已经清除了迁移表条目,清除了缓存/配置/等。

我还运行了“composer dump-autoload”,但它并没有改变结果。

每次我运行 php artisan migrate:fresh --seed 时,它都会在迁移文件上出错,从技术上讲,该文件不再存在。

我一直在搜索,但没有找到涵盖这种情况的任何内容。

php artisan migrate:fresh --seed 的输出如下:

> php artisan migrate:fresh --seed
Dropped all tables successfully.
Migration table created successfully.
Loading stored database schema: C:\Users\philc\Dropbox\heroku_git\mCentric\datab
ase\schema/mysql-schema.dump
Loaded stored database schema. (3,774.21ms)
Migrating: 2016_03_01_193027_create_sent_emails_table

   Illuminate\Database\QueryException

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'sent_emails' a
lready exists (SQL: create table `sent_emails` (`id` int unsigned not null auto_
increment primary key, `hash` char(32) not null, `headers` text null, `sender` v
archar(255) null, `recipient` varchar(255) null, `subject` varchar(255) null, `c
ontent` text null, `opens` int null, `clicks` int null, `created_at` timestamp n
ull, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4
_unicode_ci')

  at C:\Users\philc\Dropbox\heroku_git\mCentric\vendor\laravel\framework\src\Ill
uminate\Database\Connection.php:692
    688▕         // If an exception occurs when attempting to run a query, we'll
 format the error
    689▕         // message to include the bindings with SQL, which will make th
is exception a
    690▕         // lot more helpful to the developer instead of just the databa
se's errors.
    691▕         catch (Exception $e) {
  ➜ 692▕             throw new QueryException(
    693▕                 $query, $this->prepareBindings($bindings), $e
    694▕             );
    695▕         }
    696▕     }

  1   C:\Users\philc\Dropbox\heroku_git\mCentric\vendor\laravel\framework\src\Il
luminate\Database\Connection.php:485
      PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 T
able 'sent_emails' already exists")

  2   C:\Users\philc\Dropbox\heroku_git\mCentric\vendor\laravel\framework\src\Il
luminate\Database\Connection.php:485
      PDOStatement::execute()

当然,引用的 sent_email 表在数据库中,但我的迁移文件夹只有 2 个迁移文件,用于未包含在 schema.php 文件中的表。

我看到(在某个地方,但我忘记了在哪里)因为这些迁移文件可能存在于其他 git 分支中,这可能是导致错误的原因。

有谁知道这是否可能/真实?

标签: phpmigrationlaravel-8

解决方案


推荐阅读