52

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

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 migrations table in the database is empty and the new table isn't created neither. I don't understand why the documentation says foo in the path. What does foo mean and where does it comes from? First I tought that the path is wrong because of the foo thing and as I know the path is relative to the app folder so I changed it to app/database/migrations but it doesn't work. I also tried a lot of other path combination but none of them worked.

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

Laurence
  • 58,936
  • 21
  • 171
  • 212
totymedli
  • 29,531
  • 22
  • 131
  • 165
  • 1
    if you keep your migrations in `app/database/migrations`, you should be able to ignore the path parameter entirely – Jeff Lambert Jan 21 '14 at 19:11

13 Answers13

61

Try this:

First:

php artisan migrate:reset

Rolled back: 2014_03_28_142140_user_table

Nothing to rollback.

second:

php artisan migrate

Migrated: 2014_03_28_142140_user_table

check the database.

jminkler
  • 718
  • 1
  • 6
  • 15
user3474053
  • 619
  • 1
  • 5
  • 2
21

That foo thing is just an example. Laravel will look for migrations to run in app/database/migrations on default. Try removing that --path parameter and see if it works.

AntonNiklasson
  • 1,719
  • 1
  • 15
  • 28
  • Shouldn't that run all the migrations? I need to run only the last one because the project has a lot of older ones that are now wrong. – totymedli Jan 21 '14 at 19:14
  • 15
    The thing about migrations is that they are supposed to work as a batch. You should be able to run `php artisan migrate:refresh` without any troubles. So with that in mind, I would say remove/move those broken ones and keep the nice ones. – AntonNiklasson Jan 21 '14 at 19:18
  • 1
    Oh, I just realized that I mixed up the chapters in the documentation. I tought I can run a specific migration by passing the path, but it was actually the migration creation example. What a fail. – totymedli Jan 21 '14 at 19:23
  • @AntonNiklasson That command will most definitely give you troubles on a production DB, unless your definition of trouble somehow doesn't include dropping all your live data. – Hashim Aziz Mar 02 '23 at 21:55
16

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

Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113
11

What helped me:

php artisan config:cache
php artisan migrate
Jan Żankowski
  • 8,690
  • 7
  • 38
  • 52
11

need to delete 2014_01_21_143531_create_teams_table of migrations table.

  1. go to database(phpmyadmin)
  2. open your database name. 3.open migrations table.
  3. delete the 2014_01_21_143531_create_teams_table row
anurag dhiwar
  • 111
  • 1
  • 2
10

The path argument is for creating a migration for example:

 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.

Dropping the --path argument should work in your case

jminkler
  • 718
  • 1
  • 6
  • 15
4

For anyone who still cannot migrate their database:

Assume you have a file to migrate 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/.

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

Done. Hope it helps.

GameO7er
  • 2,028
  • 1
  • 18
  • 33
Ras
  • 159
  • 2
  • 5
3

use

php artisan migrate:fresh

it would refresh your database and run your all migrations again

Note:, don't do this in production, it will wipe your all your data. so before running this command do have a backup of your data. in fact, have backup data whenever you are touching database in production.

rajeshtva
  • 410
  • 6
  • 18
aaryaa9978
  • 81
  • 4
1

At least in Laravel 7, you have to add ".php" at the end of the name of the migration.

Example:

php artisan migrate --path=database/migrations/yyyy_mm_dd_table_name.php

Hope this answer help somebody.

gasgen
  • 319
  • 1
  • 2
  • 14
1

All you need to do is refresh the migration

    php artisan migrate:refresh --path=app/foo/migrations/2014_01_21_143531_create_teams_table.php
  • 1
    As of laravel 9 this refreshes other migrations as well. Not a good idea, this command. – sba Mar 01 '23 at 07:56
1

What's happening here is the filename for the migration is cached, and so even though you are changing the migration file, it is not seeing any changes, and so thinks there is nothing to migrate.

There's two ways to fix this:

You can change the file name slightly from from 2014_01_21_143531_create_teams_table.php to 2014_01_21_143532_create_teams_table.php (incrementing the number by 1) and then run php artisan migrate...

or

You can run php artisan optimize:clear to flush the cache and then run php artisan migrate:fresh to do a fresh migration.

Hope this helps!

DeviOus
  • 11
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 03 '22 at 10:13
0

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

$ 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 (id int unsigned not null auto_incr ement primary key, name varchar(255) not null, email varchar(255) not n ull, password varchar(255) not null, remember_token varchar(100) null, created_at timestamp null, updated_at timestamp 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

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

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

/**
  * Reverse the migrations.
  *
  * @return void
  */
public function down()
{
    Schema::dropIfExists('ABC');
}
Nɪsʜᴀɴᴛʜ ॐ
  • 2,756
  • 4
  • 33
  • 57
0

In my case, i just had to delete a row from my migrations table and then execute

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