php Laravel 的 Artisan 对迁移无话可说

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21266956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:58:30  来源:igfitidea点击:

Laravel's Artisan says nothing to migrate

phplaraveldatabase-migration

提问by totymedli

I installed migrations with php artisan migrate:installthen created a migration with the php artisan migrate:make create_teams_tablecommand. Now I try to run them with the following command that I made according to the official documentation:

我安装了迁移,php artisan migrate:install然后使用php artisan migrate:make create_teams_table命令创建了迁移。现在我尝试使用我根据官方文档制作的以下命令运行它们:

php artisan migrate --path=app/foo/migrations/2014_01_21_143531_create_teams_table.php

This gives me the following on the console:

这在控制台上给了我以下内容:

Nothing to migrate.

没什么好迁移的。

The migrationstable in the database is empty and the new table isn't created neither. I don't understand why the documentation says fooin the path. What does foomean and where does it comes from? First I tought that the path is wrong because of the foothing and as I know the path is relative to the appfolder so I changed it to app/database/migrationsbut it doesn't work. I also tried a lot of other path combination but none of them worked.

migrations数据库中的表是空的,也没有创建新表。我不明白为什么文档foo在路径中说。是什么foo意思,它来自哪里?首先,我认为路径是错误的,因为foo我知道路径是相对于app文件夹的,所以我将其更改为app/database/migrations但它不起作用。我还尝试了很多其他路径组合,但都没有奏效。

Did I entered the wrong path? In this case shouldn't the console show some other kind of helpfull message? What does foomean? How can I run my migration?

我是不是走错路了?在这种情况下,控制台不应该显示其他一些有用的消息吗?什么foo意思?如何运行迁移?

采纳答案by AntonNiklasson

That foothing is just an example. Laravel will look for migrations to run in app/database/migrationson default. Try removing that --pathparameter and see if it works.

foo件事只是一个例子。Laravel 将寻找迁移以在app/database/migrations默认情况下运行。尝试删除该--path参数,看看它是否有效。

回答by user3474053

Try this:

尝试这个:

First:

第一的:

php artisan migrate:reset

Rolled back: 2014_03_28_142140_user_table

回滚: 2014_03_28_142140_user_table

Nothing to rollback.

没什么可回滚的。

second:

第二:

php artisan migrate

Migrated: 2014_03_28_142140_user_table

迁移: 2014_03_28_142140_user_table

check the database.

检查数据库。

回答by jminkler

The path argument is for creating a migration for example:

path 参数用于创建迁移,例如:

 php artisan migrate:make create_user_table --path=app/database/migrations/user_migrations/

But it is not documented to use while running the migrations, as it was in prior versions of laravel.

但是没有记录在运行迁移时使用它,就像在 laravel 的早期版本中一样。

Dropping the --path argument should work in your case

删除 --path 参数应该适用于您的情况

回答by Jan ?ankowski

What helped me:

什么帮助了我:

php artisan config:cache
php artisan migrate

回答by Vahid Amiri

You don't need to move the migration file anywhere, just change its filename; for example, increase time integer and then run the migratecommand with path pointing the migration. e.g: php artisan migrate --path="database/migrations/2019_07_06_145857_create_products_table.php"

您不需要将迁移文件移动到任何地方,只需更改其文件名即可;例如,增加时间整数,然后migrate使用指向迁移的路径运行命令。例如:php artisan migrate --path="database/migrations/2019_07_06_145857_create_products_table.php"

回答by Ras

For anyone who still cannot migrate their database:

对于仍然无法迁移数据库的任何人:

Assume you have a file to migrate abc_migrate.php.

假设您有一个要迁移的文件abc_migrate.php

Firstly put your file inside the new folder named abc_folder. Then, enter this command php artisan migrate --path=database/migrations/abc_folder/.

首先将您的文件放在名为abc_folder. 然后,输入此命令 php artisan migrate --path=database/migrations/abc_folder/

You don't have to add file name at last of the directory path.

您不必在目录路径的最后添加文件名。

Done. Hope it helps.

完毕。希望能帮助到你。

回答by N?s????? ?

The problem arises if the migrationstable in the database is empty. So the solution is open up the tinker from the composer

如果migrations数据库中的表为空,就会出现问题。所以解决方案是打开作曲家的修补程序

$ php artisan tinker
>>> Schema::drop('users')
>>> Schema::drop('password_resets')
>>> Schema::drop('orders')
>>> exit
php artisan migrate

Here is the result of the above commands executed

下面是上面命令的执行结果

nishanth@localhost:~/Desktop/html/hutch$ php artisan migrate

In Connection.php line 647: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table users(idint unsigned not null auto_incr ement primary key, namevarchar(255) not null, emailvarchar(255) not n ull, passwordvarchar(255) not null, remember_tokenvarchar(100) null, created_attimestamp null, updated_attimestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

In Connection.php line 449: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists

在 Connection.php 第 647 行:SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table users( idint unsigned not null auto_incr ement primary key, namevarchar(255) not null, emailvarchar (255) not n ull, passwordvarchar(255) not null, remember_tokenvarchar(100) null, created_attimestamp null, updated_attimestamp null) 默认字符集 utf8mb4 collat​​e utf8mb4_unicode_ci)

在 Connection.php 第 449 行:SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists

nishanth@localhost:~/Desktop/html/hutch$ php artisan migrate:rollback
Nothing to rollback.
nishanth@localhost:~/Desktop/html/hutch$ php artisan tinker
Psy Shell v0.8.17 (PHP 7.1.20-1+ubuntu16.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
>>> Schema::drop('password_resets')
=> null
>>> Schema::drop('orders')
=> null
>>> exit
Exit:  Goodbye.
nishanth@localhost:~/Desktop/html/hutch$ php artisan migrate
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Migrating: 2018_08_18_071213_create_orders_table
Migrated:  2018_08_18_071213_create_orders_table
nishanth@localhost:~/Desktop/html/hutch$ 

Also define the method down(), if it doesn't exist.
Otherwise, it'll show

还要定义方法down(),如果它不存在。
否则会显示

SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'XYZ.ABC' (SQL: drop table ABC)

SQLSTATE[42S02]:未找到基表或视图:1051 未知表 'XYZ.ABC'(SQL:删除表ABC

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