Im new to laravel, someone asked me to modify in his project, these modifications need to have new tables, I created tables directly on phpmyadmin, these tables include countries and regions tables which have huge rows, I wanted to push the project to the server but don't have access to the database so must using migrate, my questions are:
how can I migrate the tables I created in phpmyadmin? I didnt create tables using the command artisan migrate.
how can I push countries and regions tables contents?
thank you in advance
Firstly familarise yourself with the documentation on Laravel Migrations (https://laravel.com/docs/6.x/migrations). The documenation is excellent!
If you want to replicate the structure of the table you have already created, I would start by getting the table schema from phpmyadmin and then simply walking through it line by line and finding the appropriate methods in the documentation.
Once you have matched the table structure, it then just a case of taking a database dump of your existing table and importing it.
To update the production server database you still can use migrations, even if you created tables manually on local environment.
Please read the docs for more info.
Run the command: php artisan make:migration table-name in local environment, and write required columns in created file.
After that, you can upload this file on the server and just run: php artisan migrate this will create tables on the prod database.
To automatically insert data after migrations you can use seeding: https://laravel.com/docs/5.7/seeding
This is not a correct approach, If you are using Laravel and manually uploading the data.
The better solution is to write the migrations and seeder.
You can print db result in an array and paste everything in your Seeder file, Check the syntax on Laravel website
Related
Me and some friends are working on a PHP page and we need a MySql database(we need to present the xampp localhost version). Since we will all make edits there we need a way to somehow update our local database with others work when they do it.
I tried to export the database from them and import in my phpmyadmin but for this I have to delete my old database. Isn't there a method to just update it? I mean what can they make to send me a file with an update and how can I import just an update?
I tried to search the answer for hours but couldn't find something specific.
I think the main problem is to synchronize database table changes, not data.
You must read about migrations and don't interact database directly from PHPMyAdmin.
Phinx is the most popular tool in PHP about migrations.
https://phinx.org/
I'm using Laravel 5.8 and each time I create a new migration I run php artisan migrate:refresh to update my database. I lose data stored in tables that already exist. I want to find a solution to add a new table without losing my data.
You can run php artisan migrate (without :refresh), this only runs migrations that have not been run yet.
The idea with migrations is that you do not edit them after you run them.
More info on migrations can be found in the migration documentation
You can use the seeding too if you need some base data when you make a migration:refresh, please see the link to know more about that.
So, I've copied a database off a server that I'm working on and I've just started working on it. However for some reason the migrations table is empty so when I try to run php artisan migrate it can't because it doesn't know that all the tables are already created. Is there a quick way of fixing this rather then adding in the name of every migration to the table manually as there are a lot of migrations in this project?
Thanks.
You can work around it the following way:
Create another empty database.
Switch your application to use the new database.
Run php artisan migrate
Copy migrations table from new database to the old one
Switch your application to use the old database again.
You could also delete existing migration files (bad idea) or move them to some other folder so that migrate command doesn't see them.
You could also fill the table yourself, but that seems pretty time consuming.
Why is that table empty in the first place? Is it empty on your server as well?
So I have set up my homestead so that I have two sites with two separate DB's. I can go to both sites separately when I run homestead up and can make changes to one site separately from the other. But when I try to do a simple migration of the in box create_user_table on the 2nd site it says there is nothing to migrate. I run migrate:status and it says both migrations (create_user_table and create_passworde_resets_table) have been made but nothing is showing up in 2nd my database.
I have a hunch that my 2nd site is still pointing to the first DB because when I run migrate:rollback I get a message that a class from my other project can't be found. How can I point my 2nd project at my 2nd DB?
p.s. I know the 2nd DB exists because I used sequel pro to login to my VM and I see that both DB's are there
Ok I figured it out. I had to go into my .env file and edit the DB_DATABASE variable to the proper database name.
Firstly I'm not an expert in Yii, MySQL or PHP.
I'm designing my database tables with MySQL Workbench, I'm not able to avoid that the Workbench creating more than a primary index so CRUD doesn't work properly. Now I'm trying to convert the MySQL code to create the tables in the create tool of Yii syntax. Are there any programs or extensions to do this automatically?
http://www.yiiframework.com/extension/database-command/
You can use that to create a dump of the database as a Yii migration (that's a bunch of PHP code with the MySQL commands to install your database). Migrations can then be imported using yiic migrate, assuming they're in the migrations folder, or by also providing a migration path (default location for dumps from that extension is the runtime folder).
Next you'll probably want to create a new migrations for all your database changes. See the database migrations guide for more info on how to do that.