Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Last update: May 15, 2022

Laravel Migrations Generator

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads License

Generate Laravel Migrations from an existing database, including indexes and foreign keys!

Upgrading to Laravel 5.4

Please note that the Laravel 4 Generator edits have been moved to https://github.com/xethron/Laravel-4-Generators.git to update compatibility.

Laravel 5 installation

The recommended way to install this is through composer:

composer require --dev "xethron/migrations-generator"

In Laravel 5.5 the service providers will automatically get registered.

In older versions of the framework edit config/app.php and add this to providers section:

Way\Generators\GeneratorsServiceProvider::class,
Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,

If you want this lib only for dev, you can add the following code to your app/Providers/AppServiceProvider.php file, within the register() method:

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Way\Generators\GeneratorsServiceProvider::class);
        $this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
    }
    // ...
}

Notes:

  • Thanks to @jamisonvalenta, you can now generate Migrations in Laravel 5!
  • feature/laravel-five-stable was forked from way/generators 3.0.3 and was made Laravel 5.0 ready. Jeffrey Way has discontinued support for Laravel 5, so the other artisan generate: commands may not have been made 5.0 compatible. Investigate the artisan make: commands for substitutes, contribute to Laravel to extend generation support, or fix it and submit a PR to jamisonvalenta/feature/laravel-five-stable.

Laravel 4 installation

Run the following composer command:

composer require --dev "xethron/migrations-generator:~1.3.0"

Next, add the following service providers:

'Way\Generators\GeneratorsServiceProvider',
'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',

And you're set. To double check if its working, run php artisan, and look for the command migrate:generate

Usage

To generate migrations from a database, you need to have your database setup in Laravel's Config.

Run php artisan migrate:generate to create migrations for all the tables, or you can specify the tables you wish to generate using php artisan migrate:generate table1,table2,table3,table4,table5. You can also ignore tables with --ignore="table3,table4,table5"

Laravel Migrations Generator will first generate all the tables, columns and indexes, and afterwards setup all the foreign key constraints. So make sure you include all the tables listed in the foreign keys so that they are present when the foreign keys are created.

You can also specify the connection name if you are not using your default connection with --connection="connection_name"

Run php artisan help migrate:generate for a list of options.

Check out Chung Tran's blog post for a quick step by step introduction: Generate Migrations from an existing database in Laravel 4

Changelog

Changelog for Laravel Migrations Generator

20 November 2016: v2.0.0

  • Support for Laravel 5

20 November 2016: v1.3.0

  • Add options --defaultIndexNames and --defaultFKNames to use Laravel's default generated names
  • --no-interaction support
  • Migrate table field comments
  • Add connection to migrations if its not the default
  • Bugfix:
    • --ignore doesn't ignoring the first table in the list
    • Remove backticks from index names #17
    • Drop foreign keys used incorrect key name #34
    • Remove table prefix from migrations
    • Escape table names and args
    • Map JSON columns as text
    • Boolean default results in empty string

25 July: v1.2.2

  • Support for Laravel 4.2
  • Support for named foreign keys
  • Fix error with --ignore option

29 May: v1.2.1

  • Fixed problem with char fields showing up as varchar
  • Allow decimal, float, and double to be unsigned
  • Allow cascading on foreign key update/delete

16 May: v1.2.0

  • Now fully supports for enum fields
  • Add support for bit fields as Boolean (Laravel Migration Limitation)

10 May: v1.1.1

  • Fix crash when migrating tables that use enum
  • Added Tests
  • Major refactoring of the code

24 March: v1.1.0

  • Ability to add entries into the Migrations Table, so that they won't be run as they already exist.
  • Convert Blobs to Binary fields
  • Minor Code Changes

Thank You

Thanks to Jeffrey Way for his amazing Laravel-4-Generators package. This package depends greatly on his work.

Contributors

Bernhard Breytenbach (@BBreyten)

License

The Laravel Migrations Generator is open-sourced software licensed under the MIT license

GitHub

https://github.com/Xethron/migrations-generator
Comments
  • 1. laravel 5 not install

    composer update Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Installation request for xethron/migrations-generator dev-l5 -> satisfiable by xethron/migrations-generator[dev-l5]. - xethron/migrations-generator dev-l5 requires way/generators dev-feature/laravel-five-stable -> no matching package found.

    Potential causes:

    • A typo in the package name
    • The package is not available in a stable-enough version according to your minimum-stability setting see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

    Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

    Reviewed by un1ko85 at 2015-02-20 20:42
  • 2. Backticks around index names are MySQL specific

    The generated migrations have backticks in the index names, like this:

    $table->integer('affiliate_id')->index('`affiliate_actions_affiliate_id`');
    

    These cause errors in PostgreSQL, as the backtick character is not ANSI SQL, and is specific to MySQL only.

    Error text in console from Artisan:

      [Illuminate\Database\QueryException]
      SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "`"
      LINE 1: create index `admins_user_id` on "admins" ("user_id")
                           ^ (SQL: create index `admins_user_id` on "admins" ("user_id"))
    

    Index names without the backticks works fine, however:

    $table->integer('affiliate_id')->index('affiliate_actions_affiliate_id');
    
    Reviewed by vlucas at 2014-07-21 22:59
  • 3. Laravel 5.4 support

    Aftr adding Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class into app.php and running php artisan I am getting:

      [Symfony\Component\Debug\Exception\FatalThrowableError]
      Call to undefined method Illuminate\Foundation\Application::share()
    
    Reviewed by denis-chmel at 2017-02-02 18:44
  • 4. boolean field is not migrated properly

    I have a table with boolean field with default value set as false. When I run migration it shows $table->boolean('deleted')->default(''); default is shown as null field. Can you please check and let me know a solution for same

    Reviewed by rebin at 2014-09-29 10:02
  • 5. migrate:generate fails with Way\Generators\Filesystem\FileNotFound error

    I'm trying to run this command:

    php artisan migrate:generate
    

    and it fails with this output:

    $ php artisan migrate:generate
    Using connection: mysql
    
    Generating migrations for: group_product_assoc, groups, product_hierarchy_assoc, product_product_assoc, products, replist, sessionsOLD, stores, tree, users, zipcode_coordinates
    
     Do you want to log these migrations in the migrations table? [Y/n] :
     > n
    
    Setting up Tables and Index Migrations
    
                                                                                             
      [Way\Generators\Filesystem\FileNotFound]                                               
      /var/www/my-project/vendor/way/generators/src/Way/Generators/templates/migration.txt  
        
    

    I'm running this on a virtual machine running Ubuntu 16.04 with php 7.0.15. My laravel version is 5.4.

    How can I fix this?

    Reviewed by sneakyimp at 2017-02-24 23:36
  • 6. Is this work for SQL SERVER

    I have application using C# and SQL server , now i want to generate model from SQL Server exists database and re-create on MySQL, is this work for SQL Server? Thanks

    Reviewed by animexxx at 2015-04-24 10:26
  • 7. Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Installation request for xethron/migrations-generator dev-master -> satisfiable by xethron/migrations-generator[dev-master]. - xethron/migrations-generator dev-master requires way/generators 2.* -> no matching package found.

    Potential causes:

    • A typo in the package name
    • The package is not available in a stable-enough version according to your minimum-stability setting see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

    Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

    In my composer file: "require-dev": { "way/generators": "~3.0", "xethron/migrations-generator": "dev-master" }

    Reviewed by itsazzad at 2015-02-02 11:14
  • 8. Feature/laravel five

    This PR addresses the changes needed to get this package to load happily in Laravel 5.0. I'm not making any claim that this work should be 'good enough' for a new stable rev, but as a stop-gap solution until a rewrite/re-integration of this package can be managed.

    Notable changes include composer dependencies and how package service providers are loaded.

    I've also done a very basic update to the broken aspects of way/generators to get it to function in 5.0. My work is based off of the 3.3 tagged commit, which was as far as Jeffrey Way pushed until he dropped L5 support. To the best of my testing this is sufficient for the needs of migrations-generator. I've updated the composer.json to point to my fork of way/generators. The only changes necessary for generators to work were config registration and dropping the $this->package() call in the Service Provider.

    No changes to the readme.md are necessary. There may well be conflicts/bugs with anyone who needs to use way/generators for work outside of this package.

    Reviewed by jamisonvalenta at 2015-02-17 06:43
  • 9. enum support?

    I'm running into this error:

    [Doctrine\DBAL\DBALException]                                                
      Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform  
       may not support it.              
    

    My tables have enum() types.

    Reviewed by jaketoolson at 2014-04-18 18:58
  • 10. Laravel 5.1 Way\Generators migration.txt template file not found problem.

    Hey @Xethron,

    I wanted use your package with Laravel 5.1. When I run artisan migrate:generate command. This error appeared.

    [Way\Generators\Filesystem\FileNotFound] .../vendor/way/generators/src/Way/Generators/templates/migration.txt

    Seems like you extended Way\generators under your username But migration template path is hardcoded so it prompts error because of path does not exists. Also I can not install way\generators for laravel 5 because of original way\generators require's laravel 4 packages.

    Reviewed by candasm at 2017-02-22 12:03
  • 11. added support for named foreign keys

    Thanks for your reverse migration generator, it works pretty well.

    When foreign key naming in the existing database differs from the common laravel syntax, the dropForeign() statements are wrong. I've fixed this so that the name of a foreign key is taken from the existing database.

    Unfortunately, on MySQL, one still needs to add $table->engine ='InnoDB'; manually to the migrations create statements. I did not found a way the get the storage engine (in case of MySQL) from the existing table via doctrine/dbal.

    Reviewed by virtualize at 2014-07-23 09:47
  • 12. remove quotation from tablename if exit

    I've removed quotation mark if exist in tablename value. facing as issue during generation of file and also tablename

    Database : PostgreSQL

    I am using PostgreSQL, Ive created table in capital letters "SERP_feature" image

    When I have tried to generate migration file throw an error because filename must not include quotation mark

    filename must be create_SERP_feature_table.php, where it takes create_"SERP_feature"_table.php

    image

    So, Pls accept my pull request and issue will resolve

    Thank you,

    Reviewed by RomikMakavana at 2020-10-02 19:57
  • 13. Undefined property: stdClass::$column_name

    I get this error on tables with enums:

    Undefined property: stdClass::$column_name at /Users/apple/Desktop/HMS/vendor/xethron/migrations-generator/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php:76)"} []

    Reviewed by acushlakoncept at 2020-05-18 06:44
  • 14. 'migrations' table was not updated

    After I ran php artisan migrate:generate After running the command `php artisan migrate:generate`` the process created files for me but did not update the 'migrations' table in DB.

    Reviewed by dordana at 2020-05-14 13:02
  • 15. Not working for Laravel 5.8

    By running this command composer require --dev "xethron/migrations-generator:~1.3.0"

    i've got this result:

    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for xethron/migrations-generator ~1.3.0 -> satisfiable by xethron/migrations-generator[v1.3.0].
        - Conclusion: remove laravel/framework v5.8.37
        - Conclusion: don't install laravel/framework v5.8.37
        - xethron/migrations-generator v1.3.0 requires illuminate/support ~4.1 -> satisfiable by illuminate/support[4.1.x-dev, 4.2.x-dev, v4.1.0, v4.1.1, v4.1.10,
    v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.0-BETA1, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
        - don't install illuminate/support 4.1.x-dev|don't install laravel/framework v5.8.37
        - don't install illuminate/support 4.2.x-dev|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.0|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.1|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.10|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.11|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.12|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.13|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.14|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.15|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.16|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.17|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.18|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.19|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.2|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.20|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.21|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.22|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.23|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.24|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.25|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.26|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.27|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.28|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.29|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.3|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.30|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.4|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.5|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.6|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.7|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.8|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.1.9|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.0-BETA1|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.1|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.12|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.16|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.17|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.2|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.3|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.4|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.5|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.6|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.7|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.8|don't install laravel/framework v5.8.37
        - don't install illuminate/support v4.2.9|don't install laravel/framework v5.8.37
        - Installation request for laravel/framework (locked at v5.8.37, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.37].
    
    
    Installation failed, reverting ./composer.json to its original content.
    
    
    Reviewed by mohsenuss91 at 2020-03-16 10:15
[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

May 1, 2022
An easy-to-use Artisan command to create a new database schema.

Laravel Create DB This package adds an easy-to-use Artisan command to your application that allows you to create a new database schema. The package is

Oct 3, 2021
PHP Database Migrations for Everyone
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

May 22, 2022
Laravel Code Generator based on MySQL Database

Laravel Code Generator Do you have a well structed database and you want to make a Laravel Application on top of it. By using this tools you can gener

May 13, 2022
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7

Maghead 4.0.x IS CURRENTLY UNDER HEAVY DEVELOPMENT, API IS NOT STABLE Maghead is an open-source Object-Relational Mapping (ORM) designed for PHP7. Mag

Apr 23, 2022
📐 Symfony Bundle to generate database diagrams
📐 Symfony Bundle to generate database diagrams

Doctrine Diagram Bundle ?? Symfony Bundle to generate database diagrams.

Jan 13, 2022
Extract SQL statements from migrations

This is my package MigrationToSql To install: composer require bcleverly/migrationtosql --dev This repo is here to help you extract the SQL queries fr

Apr 15, 2022
Migrations for MongoDB based on PHPMongo ODM

PHPMongo Migrator Migrations for MongoDB based on PHPMongo ODM Schema not required in MongoDb, so we dont need to create databases, collections or alt

Jan 31, 2022
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Please give it a Star if you like the project ?? ❤️ SleekDB - A NoSQL Database made using PHP Full documentation: https://sleekdb.github.io/ SleekDB i

May 20, 2022
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

May 23, 2022
Adminer database management tool for your Laravel application.

Laravel Adminer Adminer database management tool for your Laravel application. Table of Contents Introduction Features Installation CSRF token middlew

May 4, 2022
Laravel Inverse Seed Generator

Inverse seed generator (iSeed) is a Laravel package that provides a method to generate a new seed file based on data from the existing database table.

May 23, 2022
Clean up your Magento database by removing orphaned, unused and wrongly added attribute, attribute values and settings (for M2).

Magento 2 EAV Cleaner Console Command Purpose of this project is to check for different flaws that can occur due to EAV and provide cleanup functions.

May 11, 2022
Seed your database with CSV files

CSV Seeder Seed your database with CSV files This package allows CSV based seeds. Installation Require this package in your composer.json and run comp

Feb 16, 2022
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.
Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster.

Laravel Thermite Laravel Thermite is an extended PostgreSQL Laravel database driver to connect to a CockroachDB cluster. ?? Supporting If you are usin

Apr 6, 2022
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.

Laravel showsql A Laravel package to output a specific sql to your favourite debugging tool, your browser or your log file. Use case You often want to

Apr 15, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

May 17, 2022
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Apr 23, 2022
A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Eloquence Eloquence is a package to extend Laravel's base Eloquent models and functionality. It provides a number of utilities and classes to work wit

May 1, 2022