Why does table need to exist to run php artisan commands Laravel? - mysql

I am wondering why I can't run php artisan commands on my recently cloned laravel project. I get an error SQLSTATE[42S02]: Base table or view not found:. I don't get why this is occurring, as I'm trying to run php artisan migrate after having created the database on this machine. Of course the base table or view is not found... Why would this happen and how can I solve the problem?

Related

laravel - mysql - how to migrate tables

my problem ... i can't migrate from mysql to laravel
i am working on MySQL database and i have a lot of tables i tried to migrate those table to laravel but it doesn't work
my steps was like that:
1-create the table in mysql database
2-opened laravel and write in the .env file the database credentials then i write .. php artisan migrate in the cmd
it says nothing to migrate
all i want is to have the same tables in mysql database to be in my laravel project
There is migrations table in your database which contains the names of the migrations that were already run and exist. So what you need is just to create the database with no tables in it, create your migrations and run php artisan migrate this will run all of your migration files and will create the tables for you.

Tables not showing in database

I have already migrated the table, then added columns to it. Then again migrated it. But, it says
Nothing to migrate
and, it doesn't even show my table, and it's columns. We three people are working on it and the database is hosted on another server.
When I try to rollback, it shows error:
[ErrorException]
Undefined index: 2017_01_07_071008_create_user_detail_table
And this migration is created by my friend on her computer.
What's the problem here, I don't understand.
Please Help.
You should create another migration to add columns to created table and then run:
composer dumpauto
php artisan migrate
Or you can recreate all tables:
php artisan migrate:refresh
In this case all data will be lost.

rails db:migrate doesn't work after altering the database manually

I am still new to rails and I have some questions regarding rails migration.
I am using rails 5, windows 8. I generated a model and wrote some code which creates a table with columns. Then I deleted that table from my development db (MySQL) and tried to execute db:migrate again to see if it would create the table and columns written in the migration file. After executing db:migrate, it didn't show any messages in the terminal and it did not create the table and the columns.
Based from my observation, deleting the version of my migration file from schema_migrations and running db:migrate once again, it worked and created the table and columns.
I would like to ask the pros of rails development on why is this happening and what should I do when I start to develop a large database model.
I would also like some suggestions about great resource materials for learning ruby on rails.
Thanks!
Its because rake db:migrate is running only migrations for the current env that have not run yet. So if you run db:migrate and then manually delete table form DB, your app does not know that.
MIgration Guides

Laravel artisan migrate

I'm working on a site with the latest version of laravel, and we have recently changed the MySQL DB location from a remote host to a local host. After moving and editing the config/database.php file to reflect the changes, I tried to run the command php artisan migrate, but I'm not getting anything back.
There is no response on the terminal, and no results in the new database. I've also tried migrate:refresh and migrate:status.
How do I re-run the migrations and get the tables in the new database?
At first drop your database table or tables and than execute
php artisan migrate:refresh
hopefully it'll work for you
You can just export DB to a file and import it on a local host. You do not need to run php artisan migrate command.
You do not want to run migrations if you already have DB with tables and data.

rails: changing database

I have created an app using a badly named database, all alterations to important data in the database have been done in fixtures so that I can just drop the database, recreate it and then rake migrate the database tables and fill them with the initial data from the fixtures.
I would like to change the name of my database now, so I updated the database.yml file to reflect another database name. I created the database in mysql and then tried to run the migration and fixtures.
Running the migration with trace shows that it is running commands to create tables etc. However once I am finished I get errors in my application saying that the tables don't exist in the new database.
I go into mysql and check the database and it is completely empty. I have tried wiping everything and running the migrations a few times but nothing changes. Is there something I am missing?
I don't know what commands you used to do the migration, but to migrate a production database (which I infer from the tag, "production-environment"), you have to do:
RAILS_ENV=production rake db:migrate
If that's not the answer, then please provide the command you used to perform the migration, which database you expected to be affected, and the relevant bits of database.yml.