MySql phpmyadmin tables to Laravel migrations files - laravel

I've DB in phpmyadmin with many tables in it.
I want to auto generate those tables into seperate laravel migration files.
Does anyone know of such a possibility?

You can install package for that https://github.com/Xethron/migrations-generator

This way your migrations table will be separated for each database.
Use the --database parameter with the migrate command and store the migrations for each database in separate directories.
You could have separate directories in app/database/migrations for each of your database (for example : db1 and db2) and store the appropriate migrations in each directory. Then you could run the migrations like this:
artisan migrate --database="db1" --path="app/database/migrations/db1"
artisan migrate --database="db2" --path="app/database/migrations/db2"
If you want to go the extra mile and automate the process you could create your custom command that will run all the migrations at once. You can create the command like this:
artisan command:make MigrateAllCommand --command=migrate:all
You can check the Laravel Command Docs for more info.

Related

Laravel reduce migration files

I have a Laravel application that uses a DB. The DB is big and was produced by many migration files. Is there a way to cut down the number of migration files so that each table has one migration file? Also Would something results from having too many migration files? like performance issues?
if you have laravel 8 you can use squashing-migrations
by run php artisan schema:dump cmd
ref link https://laravel.com/docs/8.x/migrations#squashing-migrations
for older version you can try this
https://github.com/Cytracom/laravel-migration-squasher
or you can try this
Laravel 5.5 Consolidate migrations w/ production database
after laravel 8 you can run php artisan schema:dump
it change all migrations to single schema file
For more explanation check link https://advancedwebtuts.com/tutorial/what-is-the-use-of-laravel-squashing-migrations-schema-dump-command

Laravel Artisan Migrate Command creating tables but not filling every migration file to migrations table

Have been using Laravel for over a year now. My migrations folder has 39 files at the moment and i work (construct/destroy) with my database occasionally.
What happens is since ive created a "create_payments_table" migration, every migrate command that i execute builds all my tables normally but when login the migration history to my migrations table it stops at the 'create_payments_table' migration. So now when i create new migrations and run migrate again it tries to restart from my payments table which already exists giving me an error. Comparing my "create_payments_table" migration with the last logged migration file "create_pictures_table" it seems that everything is in order. Would like to know why my migrations create the tables but not all of them are been logged in migrations table?
My migrations table:
My migrations folder:
As u can see i added two new migrations and would like to run them without having to rollback my migrations table. But when doing so:
I get this error as artisan tryies to run de pauments migration again
You can migrate only a specific migration file :
php artisan migrate --path=/database/migrations/my_migration.php
Where my_migration will be your new migration file name like 2020_06_20_221554_create_additional_users_table

How to modify migrations and migrate it without loosing data?

I created a MYSQL database using migrations, I added some data into it, but after that I recognized that I need to add a new column into my table.
I ran the command: 'php artisan migrate', but as it didn't work to synchronize
columns, it returns there is nothing to migrate.
So I ran the command 'php artisan migrate:reset', and then ran the command
'php artisan migrate' again, database schema updated correctly but for sure I
lost all my inserted data.
Now I'm just testing the application, but it would be very harmful if I found out that I should modify my database while it is runing with real data!!! What should I do in this case?
should I skip using migrations and create the Mysql database directly with
wamp? or use migration, but perform any later updates directly on database without updating the migration files? or there is another solution?
Answer
If you have already created a database table and realise you need to add more into it you can simply run: php artisan make:migration add_field_to_table_name --table=tableName
You then go into that file and create the new field. Once done simply run php artisan migrate and it'll add the new field into the desired table without causing any data loss.
Seeders
On another note, I would strongly suggest looking into seeders. This way when you're creating a project you can always refresh your migrations (wipe your database and re-migrate your tables) and then re-input the data using seeders.
you can create a migration to alter your tables. add new columns and more.

Laravel 5.* modify column with migration

I have follow the laravel migration steps and its good. My problem is about on modifying the column. I already installed the doctrine\dbal in composer. But when i change the column $table->string('name')->nullable()->change() with change method, then run php artisan migrate. Is says nothing to migrate. Why? Do i need to use the doctrin\dbal like this use Doctine\dbal in the migration table class? Or what is the better way to implement for modifying the table column in migration and what artisan should i run? Any help please!
Tenancy migrations will only run once, meaning once it has been run, it will not run again once the php artisan migrate has been run. You can see all migrations which have been run in your application by viewing the migrations table in your database.
If you edit a migration file and need to re-run all your migrations you can use the following command php artisan migrate:refresh. This will rollback all your migrations and re-run them and also increment the batch number on the migrations table.
If you need to edit one of your tables but don't need to re-run all your migrations, you should create a new migration and edit the table in question in that particular migration. Once the migrate command has been run again, only your new migration will be executed.
You can find more information on all of this in the following link: https://laravel.com/docs/5.4/migrations

how to run migrate command above an existing database

I'm new using laravel and artisan migration command, and I want to create migrate files from an existing database, how can I do that ?
Laravel does not currently support this. You'll have to manually create all those files based off your schema already in your DB.

Resources