How to generate migrations based on existing tables in laravel 5.4? - laravel

I have a database and I would like to generate migration based on tables that already exists.
How can I do that?
I am running linux ubuntu 16.10 + Mariadb and laravel 5.4

A quick Google shows many packages that will do just this sort of thing for you, like migrations-generator.
You'll probably want to go over any generated migrations as well just to make sure they match what you're after.

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 Migration Advantages

I am new to using Laravel, and I'm currently learning about Laravel's database migration and seeding features.
It's working with the command prompt, but I can migrate and seed in phpMyAdmin as well. What are the advantages and disadvantages of migrating and seeding within Laravel as opposed to phpMyAdmin?
From Laravel docs on Migrations & Seeding:
Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state.
A simple search for why database migration also gives me some pretty decent results. One of the easiest to understand is a page by FlywayDB (I have no idea who they are until I search this term up):
Database migrations are a great way to regain control of this mess. They allow you to:
Recreate a database from scratch
Make it clear at all times what state a database is in
Migrate in a deterministic way from your current version of the database to a newer one
The illustration they made perhaps explain it more clearly, so you may want to check it out.

Migrations from database

I have created the schema through MySQL Workbench and synchronized it with the database.
All the tables are there in database. Now when I use the
php artisan migrate
command, is there an option to take the fields director from the database instead of specifying the fields name.
Also could you please suggest any other tools on github.
Laravel Migrations Generator will help us generate migration source code from existed database in Laravel 4.
so if you already have your sql schema, created in mysql workbench, then you'd need to put that schema into laravel migrations using the schema builder.
there are tools that make this part easier:
http://www.laravelsd.com/ - kinda like mysql workbench, with an export possibility to laravel migration code
https://github.com/XCMer/larry-four-generator writes existing databases to laravel migration code
Another option is to use our tool Skipper (https://www.skipper18.com) We introduced Laravel support a month ago and now, in a beta phase, it is free for Laraver users.
Skipper allows you to import your MySQL Workbench project directly (or it is possible to import existing database too) and then export migrations and object files from Skipper to your Laravel project.
The benefit of this solution is that you can maintain your ORM schema directly in Skipper and continuously update model object files and create new migrations automatically from the application without the necessity to write any code manually.
If you want to try it, you can download it here https://www.skipper18.com/en/download, and in the initial application license screen select "Laravel Beta license".

What is migration in laravel

I'm learning laravel and in most of tutorials they are making migrations using artisan.
I skip that step and I'm working directly on a database.
I don't know for what can a migration be useful.
so the question is: what is exactly a migration?
If you are the lone developer, you may not get much use out of it.
But imagine you have multiple developers each with your app stored locally on their machine. What happens when you need to make an update to the database? You would have to make the update, send the query to each other developer, and they would have to run the query on their machines. Once you get a decent amount of developers making changes to the database, this process can quickly become overwhelming and it's only a matter of time before people start missing the changes.
With migrations, all of the changes are stored as files, so in order for a developer to catch up, all they need to do is fetch the code changes and run php artisan migrate and all the work is done for them. This means all your developers are consistently working with the same database structure.

Getting started with Laravel and Sentry

I found a Laravel 4 announcement on HN a few weeks ago and thought I could give it a try.
After looking for a basic tutorial, I found this one:
http://www.codeforest.net/laravel4-simple-website-with-backend-1
And ran into what is probably a silly problem: the command php artisan migrate --package=cartalyst/sentry created a single table in my database when it should have created four, according to the tutorial.
Is there some step missing, or did I assume wrong when I thought it had something setup to create the needed tables?
Looking at the Sentry home I couldn´t find what I did wrong, so I´ll just look for the SQL to create the tables in the source, but I still would like to know what was the problem.
First run
php artisan migrate
Then run
php artisan migrate --package=cartalyst/sentry
After doing this it should create these tables: migrations, groups, throttle, users, user_groups
If fails again, destroy your database, re-create and re-run these steps.

Resources