SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists. I want to migrate posts table. When I do this, see the above error.
Here is my users and posts tables migration code [posts migration code][1]
You haven't showed your code but it seems your users table is already migrated. Assuming you are on localhost (no production development) you should try to run
php artisan migrate:refresh
or if it won't help you should include your migrations code
Related
Maybe someone has faced such a situation. Unfortunately, none of Stackoverflow's tips solve this. A clean project (I managed to register the routes only). With the php artisan migrate command, the migrations table is created and immediately dropped.
Error.
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main.migrations' doesn't exist...
When I use php artisan migrate:install it creates a migration table (it is visible in migrate:status, it also appears in the database). But php artisan migrate ruins it again, same error.
Neither migrate:fresh, migrate:rollback, nor composer dumpautoload helped. I've been fighting all evening, nothing helps.
I have a Laravel 5.3 site and I suspect I made some manual database changes without using the Laravel migrate functionality and now it is biting me...
Now I am trying to get to a stable database situation.
Here was my migrations folder yesterday:
create_sometable1_table
create_sometable2_table
create_sometable3_table
And so on.
Then I added via
php artisan make:migration create_newtable_table
But later renamed the migration file and the model file to create_newtabledifferentname_table
Then I tried to add another table using
php artisan make:migration create_anothertable_table
But I get
[InvalidArgumentException]
A CreateAnothertableTable migration already exists.
I ran the usual commands to try and get things into normal state, like cache:clear, and the recommended composer commands (like autoload).
But nothing works.
In my DB these tables don't exist and the migration file create_anothertable_table doesn't exist.
So I ran
php artisan migrate:rollback
And this resulted in all but 3 of my tables disappearing, with 3 now remaining in the database. The 3 remaining ones are not the ones of interest.
Anyway, I have all my tables and data on my live site and am just trying to get things locally looking the same, so no big deal that my DB on localhost is currently messed up.
Just need to know, how to get things into a stable state from this point onward?
Thanks!
Brian
i am trying to insert data in database using laravel framework. but it gives me error like sqlstate hy000 access is denied. after that i run the command php artisan migrate --env=local. after that error is removed but it created two tables automatically name: "users" and "Migrations". now i don't know why these two tables are created automatically. please help me regarding these tables. Thankyou!
users table is a default migration that exists on a fresh install of Laravel. Many sites require some kind of user login, so Laravel includes a table for users by default.
You can find this migration in database/migrations/ folder inside your Laravel project folder.
This table is used for the Laravel Auth (basic user login / registration system) which can be set up simply by typing php artisan make:auth into your terminal inside the Laravel project folder.
This will create another migration for you for password resets.
The migrations table allows Laravel to know which migrations have already been executed, so for example if you were to run php artisan migrate again after running php artisan make:auth, it would know to only run the password resets migration, as the user migration had already been completed previously.
You can read more about Laravel's migrations in the Laravel Documentation
I am new to Laravel and was working on one project, which was 90% completed, and now project is 100% completed.
The project has old Migration files. I have made so many modifications in the tables (added/deleted columns) and/or added new tables in the database, now how do I update/create the Migration for that modifications? Because I don't remember where did I made the changes in the tables.
Do I have to use artisan command to create new migration for users table and all other tables same like this? php artisan make:migration create_users_table --create=users or there is any another way?
I have read the documentation but don't get how to do it.
Please correct me if I have made any mistake, because I don't know how to ask this question.
We user migration and tinker to Not use phpmyadmin , so if you have altered your tables in any way in phpmyadmin , you are all set , no need to do anything.
If you dont want to use phpmyadmin you can use migration and then start writing the sql code in there ( altering tables , etc)
And as we know the migration php files are located in your laravelfolder/database/migration . you can edit them there and then run php artisan migration and it will go throw all of them and make the changes in phpmyadmin.
Hope im clear enough :D
I am installing Backpack package in my project, I followed the documentation steps but when I do migrate it says "Nothing to migrate".
I've already tried to publish the migrations but nothing works.
From their documentation, the only thing that you need to migrate is the default users and password reset table that comes with laravel.
php artisan migrate #generates users table (using Laravel's default migrations)
So in case if you've already migrated those, then you can skip that part. But if you haven't then make sure you have the default migrations in database/migrations and then run php artisan migrate:refresh