enriques_pr
enriques_pr

Reputation: 1

Git Cloned Laravel Project failing at php artisan migrate and php artisan db:seed

I git cloned a repository for a project written in Laravel/PHP. I was able to get most things running locally and I was able to create the initial migrations folder but I'm stuck at the seeding and table creation point (?). I keep get the following errors:

In Connection.php line 664:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lara_dev.users' doesn't exist (SQL: alter table `users` add `avatar` varchar(255   
  ) null default 'users/default.png' after `email`, add `role_id` int null after `id`)


In PDOStatement.php line 144:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lara_dev.users' doesn't exist  


In PDOStatement.php line 142:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lara_dev.users' doesn't exist  

*lara_dev is the local database's name. I created it directly in my MySQL local client terminal after git cloning the project, it was NOT created by any commands executed in the terminal.

Also:

The database folder has three folders inside: factories, migrations, and seeds. From what I see and understand, the files inside are configured correctly and the database should be created without issues and without having to edit these files.

I do NOT have a WAMP server, I'm simply using php's built in server through the command 'php artisan serve'.

Solutions I've tried so far that haven't worked:

  1. php artisan cache:clear //Clears the cache but that's about it.

  2. php artisan migrate:fresh --seed //Same errors but also drops any tables that were there before.

  3. php artisan migrate:refresh --seed // Gives 'nothing to rollback' message.

  4. php artisan db:seed //Same errors

I haven't been able to find any solutions here on Stack that work for my situation. Any help would be greatly appreciated.

Please take into account I am relatively new to PHP, but not to coding, and I've been able to get things running for the most part, I'm just stuck here. If I can provide additional information, please let me know. Thanks in advance!

Upvotes: 0

Views: 1557

Answers (4)

Mohammad Hosseini
Mohammad Hosseini

Reputation: 1797

I think I understand where your problem is. In Laravel framework we have migrations that defines in Laravel/database/migrations folder. They have specefic names.

Their names depend on the date of their creation and are arranged in the same way and executed in the same way.

For ex:

2014_10_12_000000_create_users_table.php

and

2014_10_12_000001_alter_users_table.php

create_users_table.php run in the first place and after that alter_users_table.php runs.

Your Problem:

You have a part of the code in the migrations that needs to be changed on the users table but your users table not created yet. So you have two ways:

1-change name of (date_timestamp)_create_users_table.php In such a way that the create date before the alter migration date

2-change name of migration that has those part of code that alter user table In such a way that the date after the date of the creation of the user table.

At the end run php artisan migrate:fresh

Upvotes: 0

enriques_pr
enriques_pr

Reputation: 1

Daniyal Javani gave me the right answer in the comments above. I added that exact file, https://github.com/laravel/laravel/blob/master/database/migrations/2014_10_12_000000_create_users_table.php, to my migrations folder. It created the users table I was missing and then running 'php artisan migrate' worked.

Upvotes: 0

It seems, you have issues with the order of your migrations. It is trying to alter the table before create it.

Laravel migrations will contain a timestamp which allows the framework to determine the order of the migrations

Can you change the alter users table migration file name to 2020_04_24_062125_alter_users_table.php and try again ?

Upvotes: 0

Luca Puddu
Luca Puddu

Reputation: 501

Some migration is failing because it's trying to alter the users table, which hasn't been created yet.

Make sure that the migrations are in the correct order, since they get executed in alphabetical order.

Upvotes: 2

Related Questions