Mfrancik's avatar

database migration issues

I have been using sqlite for development since I started my project and attempted to change everything to mysql with no avail. I am trying to build database in sqlite to continue dev but when running the php artisan migrate command I get:

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1 no such table: accounts (SQL: select * fr om "accounts" limit 1)

[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000]: General error: 1 no such table: accounts

[PDOException] SQLSTATE[HY000]: General error: 1 no such table: accounts

Ive changed my database config file to default = sqlite and did not change anything in the sqlite array. Ive tried deleteing the sqlite database and recreating and migrating I get the same issue.

I get the same above two errors when running just php artisan

0 likes
16 replies
fahad's avatar

Are you seeding data at the same time ??

Mfrancik's avatar

i am not using seeders to do so. I am inserting data in my users table which adds account_id. I am not inserting any data in the accounts table

fahad's avatar

in that case you need to ensure that the migration sequence

234142324234242_create_accounts_table

must comes first before your user table

( I am assuming that you have added a foreign key on the account_id column in your user table)

Mfrancik's avatar

Accounts migration does come before users table and I do have foreign key set. Everything was working fine before I attempted to switch to mysql

DB::table('users')->insert( [ 'name' => 'Mike Francik', 'email' => '[email protected]', 'userType' => 'Super_Admin', 'account_id' => '0', 'password' => bcrypt('sk84life'), ] );

fahad's avatar

do you have an existing row on your accounts table, it is not fair to use an id of 0 by the way. this way the foreign key should throw an exception.

Mittensoff's avatar

Do you have an accounts model anywhere? You have a query somewhere that does select all the data from accounts table.

Mfrancik's avatar

I was unaware of this and makes sense why I experienced some weird activity. I do not have an existing row. I made sure to delete the mysql database on my vagrant machine. I also deleted the database.sqlite file in my database directory and used touch database/database.sqlite to recreate one

Mfrancik's avatar

I do not have anything querying accounts in any of my models classes

fahad's avatar

well.. just for quick debugging purpose, you can move all of the migration files except

create_accounts_table

// and 

create_users_table

and see if the command runs successfully, and track done the rest using this approach, it might take a little longer if your have lots of table on your database, but will save you from being depressed.

Mfrancik's avatar

I have about 45 tables so it'll take me some time. I already banged my head on the wall for a couple hours on this one so I will do the above tomorrow morning (very late here). Thank you.

Mfrancik's avatar

I attempted this but still receive the same error. I want to reiterate, just to help come to a conclusion, even running just php artisan throws this same error.

Cronix's avatar

is the migrations table in the db empty? Or does it still contain migrations from when you ran migrations on the other db?

Mfrancik's avatar

The database.sqlite file is completely empty

fahad's avatar
fahad
Best Answer
Level 7

Strange, you are still getting the same error. can you please check your database configuration( .env file or config/database.php ), and do you know if some event occurs and it runs some background program to seed some data on your application( it's a strong possibility now)when the migration runs.........

you can just try by using a simple migration file to see if the command runs successfully, a really too simple table migration file may be only with 2 columns.

php artisan migrate:refresh

1 like
Mfrancik's avatar

I actually moved the database to mysql. I was having issues with foreign keys in mysql so I created a new migration files and placed all foreign keys in that file. Thank you above for the efforts.

Please or to participate in this conversation.