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

Overview

Laravel Migrations Generator

Style check CI codecov Tests CI Latest Stable Version Total Downloads License

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

This package is cloned from https://github.com/Xethron/migrations-generator and updated to support Laravel 5.6 and above, with a lot of feature improvements.

Supported Database

Currently, Generator support generate migrations from:

  • MySQL
  • PostgreSQL
  • SQL Server

Version Compatibility

Laravel Version
9.x 5.x
8.x 5.x
7.x 5.x
6.x 5.x
5.8.x 5.x
5.7.x 5.x
5.6.x 5.x
5.5 and below https://github.com/Xethron/migrations-generator

Install

The recommended way to install this is through composer:

composer require --dev "kitloong/laravel-migrations-generator"

Laravel Setup

Laravel will automatically register service provider for you.

Lumen Setup

Auto-discovery is not available in Lumen, you need some modification on bootstrap/app.php.

Enable facade

Uncomment the following line.

$app->withFacades();

Register provider

Add following line into the Register Service Providers section.

$app->register(\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);

Usage

To generate migrations from a database, you need to have your database setup in Laravel's config (config/database.php).

To create migrations for all the tables, run:

php artisan migrate:generate

You can specify the tables you wish to generate using:

php artisan migrate:generate --tables="table1,table2,table3,table4,table5"

You can also ignore tables with:

php artisan migrate:generate --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:

php artisan migrate:generate --connection="connection_name"

Squash migrations

By default, Generator will generate multiple migration files for each table.

You can squash all migrations into a single file with:

php artisan migrate:generate --squash

Options

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

Options Description
-c, --connection[=CONNECTION] The database connection to use
-t, --tables[=TABLES] A list of Tables or Views you wish to Generate Migrations for separated by a comma: users,posts,comments
-i, --ignore[=IGNORE] A list of Tables or Views you wish to ignore, separated by a comma: users,posts,comments
-p, --path[=PATH] Where should the file be created?
-tp, --template-path[=TEMPLATE-PATH] The location of the template for this generator
--date[=DATE] Migrations will be created with specified date. Views and Foreign keys will be created with + 1 second. Date should be in format suitable for Carbon::parse
--table-filename[=TABLE-FILENAME] Define table migration filename, default pattern: [datetime_prefix]\_create_[table]_table.php
--view-filename[=VIEW-FILENAME] Define view migration filename, default pattern: [datetime_prefix]\_create_[table]_view.php
--fk-filename[=FK-FILENAME] Define foreign key migration filename, default pattern: [datetime_prefix]\_add_foreign_keys_to_[table]_table.php
--default-index-names Don't use db index names for migrations
--default-fk-names Don't use db foreign key names for migrations
--use-db-collation Follow db collations for migrations
--skip-views Don't generate views
--squash Generate all migrations into a single file

Thank You

Thanks to Bernhard Breytenbach for his great work. This package is cloned from https://github.com/Xethron/migrations-generator.

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

Contributors

Contributors

License

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

Comments
  • Issue running on SQL Server

    Issue running on SQL Server

    Hello, I am running this for the first time on a SQL Server connection and I am getting the below error. I was able to get it working on a local postgres DB, but not the SQL Server connection.

    [PDOException (HY093)]
    SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

    • DB: SQL Server 2019
    • Laravel Version: 8.75.0
    • PHP Version: 8.1.9
    • Migrations Generator Version: 6.5.1
    • Doctrine DBAL Version [doctrine/dbal]: 3.5.1

    Stack Trace:

      at /vendor/doctrine/dbal/src/Driver/PDO/Statement.php:134
    
     PDOStatement->execute() at /vendor/doctrine/dbal/src/Driver/PDO/Statement.php:134
    
     Doctrine\DBAL\Driver\PDO\Statement->execute() at /vendor/doctrine/dbal/src/Driver/Middleware/AbstractStatementMiddleware.php:69
    
     Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware->execute() at /vendor/doctrine/dbal/src/Connection.php:1063
    
     Doctrine\DBAL\Connection->executeQuery() at /vendor/doctrine/dbal/src/Schema/SQLServerSchemaManager.php:406
    
     Doctrine\DBAL\Schema\SQLServerSchemaManager->selectTableNames() at /vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:356
    
     Doctrine\DBAL\Schema\AbstractSchemaManager->doListTableNames() at /vendor/doctrine/dbal/src/Schema/SQLServerSchemaManager.php:40
    
     Doctrine\DBAL\Schema\SQLServerSchemaManager->listTableNames() at /vendor/kitloong/laravel-migrations-generator/src/DBAL/DBALSchema.php:33
    
     KitLoong\MigrationsGenerator\DBAL\DBALSchema->getTableNames() at /vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php:185
    
     KitLoong\MigrationsGenerator\MigrateGenerateCommand->filterTables() at /vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php:110
    
     KitLoong\MigrationsGenerator\MigrateGenerateCommand->handle() at /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
    
    needs more info 
    opened by rotunomp 14
  • TypeError on generate migration files

    TypeError on generate migration files

    database.php

    'rwsn_sqlsrv' => [
                'driver' => 'sqlsrv',
                'url' => env('DATABASE_URL_RWSN_SQLSRV'),
                'host' => env('DB_HOST_RWSN_SQLSRV', 'localhost'),
                'port' => env('DB_PORT_RWSN_SQLSRV', '1433'),
                'database' => env('DB_DATABASE_RWSN_SQLSRV', 'forge'),
                'username' => env('DB_USERNAME_RWSN_SQLSRV', 'forge'),
                'password' => env('DB_PASSWORD_RWSN_SQLSRV', ''),
                'schema' => env('DB_SCHEMA_RWSN_SQLSRV', ''),
                'charset' => 'utf8',
                'prefix' => '',
                'prefix_indexes' => true,
            ],
    

    php artisan migrate:generate -c rwsn_sqlsrv

    Using connection: rwsn_sqlsrv
    
    
       TypeError 
    
      MigrationsGenerator\DBAL\Mapper\ViewMapper::makeView(): Argument #2 ($sql) must be of type string, null given, called in /var/www/html/server/niyam/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php on line 60
    
      at vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:77
         73▕ 
         74▕     /**
         75▕      * @throws \Doctrine\DBAL\Exception
         76▕      */
     77    private static function makeView(string $name, string $sql): View
         78▕     {
         79▕         // trim quotes
         80▕         $unquotedName = str_replace(['`', '"', '[', ']'], '', $name);
         81▕ 
    
          +3 vendor frames 
      4   [internal]:0
          MigrationsGenerator\DBAL\Schema::MigrationsGenerator\DBAL\{closure}()
    
          +18 vendor frames 
      23  artisan:37
          Illuminate\Foundation\Console\Kernel::handle()
    
    needs more info 
    opened by omidd1315 9
  • Unknown database type data requested - sqlite DB

    Unknown database type data requested - sqlite DB

    Describe the bug The following error appears and no migrations are created:

    Setting up Tables and Index Migrations
    
    In AbstractPlatform.php line 454:
    
      Unknown database type data requested, Doctrine\DBAL\Platforms\SqlitePlatform may not support it.
    

    To Reproduce Steps to reproduce the behavior: Install the package on a laravel 5.8 installation with sqlite as database.

    1. Create table celltype
    PRAGMA foreign_keys=OFF;
    BEGIN TRANSACTION;
    CREATE TABLE celltype (jobID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    title TEXT,
    email TEXT NOT NULL,
    snp2gene INTEGER,
    snp2geneTitle TEXT,
    status TEXT,
    created_at DATA NOT NULL);
    
    1. Run php artisan migrate:generate celltype
    2. See error

    Expected behavior A create migration file would be produced

    Screenshots None

    Details (please complete the following information):

    • DB: sqlite3
    • DB Version: 3
    • Laravel Version: 5.8
    • PHP Version: 7.3
    • Migrations Generator Version: 6.4.3

    Additional context NA

    needs more info 
    opened by bldrvnlw 6
  • Enhanced Checks

    Enhanced Checks

    Before I fill this out, you're welcome 100% to just ignore this feature request, but it's something I was trying to alter in your code myself, and I only managed to get one part working. The reason I am suggesting this is because we have a huge database, it was originally created by hand, then 30% of it from migrations. Now we want to go back and fix the migrations - this tool makes it possible, but every time a migration gets generated I have to manually go through and add conditional statements so that the migrations can safely run on production and not break these already existing operations. I know you would say "why don't you just add the migration list to the migrations table" - that's an easier way to do it, but I have superstitious coworkers, so we're fortifying our migrations to make sure there's only sunshine :)

    So again, the idea is for example:

    Schema::create would be wrapped in: NOT Schema::hasTable (php condition) Schema::table would be wrapped in: Schema::hasTable (php condition) Foreign Key Drop would be wrapped in: HasForeignKey (we have a helper function for this in DatabaseUtils::hasForeignKey Foreign Key Create would also be wrapped to make sure it doesn't already exist.

    And yes I could just re-run the whole database and output the migrations, that would probably be the right way to go - but we're talking about 1500 tables, 5 databases, on SQL Server 2019 - It's scary as hell to think your program would perfectly rewrite every migration in perfect order and be sound. I would be shocked, because I consider myself a senior, and the code you're writing here is senior larevel code, and I still make mistakes. It would just be shocking though if it worked perfectly with such a terrible scenario (ie: SQL Server, tons of tables, Views, Stored Procedures, Indexes, etc). It's kind of madness in our DB.

    Now for the form below - Thanks for reading all of this.

    Is your feature request related to a problem? Please describe. Not your problem, but more along the lines of more manual work I have to perform. You're getting us 99.9% there with this package, so it's not a huge burden to manually modify the files.

    Describe the solution you'd like Perhaps add an option --strict-checks, which basically makes sure any time something is created it does not exist, and any time something is dropped it hasn't already been dropped - any time something is modified, make sure it exists before changing it. The idea is to prevent failure of migration - if the migration was designed to add a column, the column shouldn't exist. This is just the nature of a dirty database and migration catch up.

    Describe alternatives you've considered Manually wrapping statements with conditional statements to get the result I need.

    Additional context Yeh I pasted a snippet below to show you what I did:

    SchemaBlueprint -- Don't worry, I butchered your nice code real good LOL, sorry. And my indentions need to be fixed grrr.

    if ($this->blueprint !== null) {
    
                // Wrap Schema Start/End added by Nathan.
                $wrap_schema_start = "if (Schema::hasTable('{$tableWithoutPrefix}')) {";
                $wrap_schema_end = '}';
                if (str_contains($schema, 'create')) {
                    $wrap_schema_start = "if (!Schema::hasTable('{$tableWithoutPrefix}')) {";
                    $wrap_schema_end = '}';
                }
    
                if ($wrap_schema_start) {
                    $lines[] = $wrap_schema_start;
                }
                $lines[] = ($wrap_schema_start ? Space::TAB() : '') . "$schema('$tableWithoutPrefix', static function (Blueprint \$table) {";
                // Add 1 tabulation to indent(prettify) blueprint definition.
                $lines[] = ($wrap_schema_start ? Space::TAB() : '') . Space::TAB() . $this->blueprint->toString();
                $lines[] = ($wrap_schema_start ? Space::TAB() : '') . "});";
                if ($wrap_schema_end) {
                    $lines[] = $wrap_schema_end;
                }
                return $lines;
            }
    

    The above code updates generated this up statement. I'm not really interested in down statements at this time, but if you do decide to make updates on my concept, it might be good to include those in the down as well. Think of it as hardening / concretely handling the migrations so they can succeed and still be effective. Order of running them is important as well.

    if (!Schema::hasTable('wh_totes')) { // THIS IS IMPORTANT
                Schema::create('wh_totes', static function (Blueprint $table) {
                    $table->bigIncrements('id');
                    $table->timestamps();
                    $table->integer('warehouse_id');
                    $table->string('name');
                    $table->float('length', 0, 0);
                    $table->float('width', 0, 0);
                    $table->float('height', 0, 0);
                    $table->boolean('can_consolidate')->default(true);
                });
            }
    
            if (Schema::hasTable('wh_totes')) { // THIS MIGHT BE IMPORTANT
                Schema::table('wh_totes', static function (Blueprint $table) {
                    
                    if (Schema::hasTable('wh_warehouses')) { // THIS IS IMPORTANT
                        $table->foreign(['warehouse_id'])->references(['id'])->on('wh_warehouses')->onUpdate('NO ACTION')->onDelete('NO ACTION');
                    }
                });
            }
    
    opened by NHuebner1983 5
  • The returned constraints doesn't have `level` key

    The returned constraints doesn't have `level` key

    Hello,

    I'm using laravel 9 + mariadb 10.5.8, when I tried to genrate the migration file form the database I've got this error, looks that the returned constraints doesn't have "level" key, check the line in bold

    [2022-10-01 08:44:07] local.ERROR: Undefined array key "level" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"level\" at /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:1679)
    [stacktrace]
    #0 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(259): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
    #1 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(1679): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
    **#2 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/Repositories/Entities/MariaDB/CheckConstraint.php(47): Illuminate\\Support\\Collection->offsetGet()**
    #3 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/Repositories/MariaDBRepository.php(29): KitLoong\\MigrationsGenerator\\Repositories\\Entities\\MariaDB\\CheckConstraint->__construct()
    #4 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/MySQL/MySQLColumn.php(161): KitLoong\\MigrationsGenerator\\Repositories\\MariaDBRepository->getCheckConstraintForJson()
    #5 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/MySQL/MySQLColumn.php(61): KitLoong\\MigrationsGenerator\\DBAL\\Models\\MySQL\\MySQLColumn->isJson()
    #6 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/DBALColumn.php(128): KitLoong\\MigrationsGenerator\\DBAL\\Models\\MySQL\\MySQLColumn->handle()
    #7 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/MySQL/MySQLTable.php(26): KitLoong\\MigrationsGenerator\\DBAL\\Models\\DBALColumn->__construct()
    #8 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/DBALTable.php(56): KitLoong\\MigrationsGenerator\\DBAL\\Models\\MySQL\\MySQLTable->makeColumn()
    #9 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(758): KitLoong\\MigrationsGenerator\\DBAL\\Models\\DBALTable->KitLoong\\MigrationsGenerator\\DBAL\\Models\\{closure}()
    #10 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/Models/DBALTable.php(59): Illuminate\\Support\\Collection->reduce()
    #11 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/DBAL/MySQLSchema.php(25): KitLoong\\MigrationsGenerator\\DBAL\\Models\\DBALTable->__construct()
    #12 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php(392): KitLoong\\MigrationsGenerator\\DBAL\\MySQLSchema->getTable()
    #13 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(262): KitLoong\\MigrationsGenerator\\MigrateGenerateCommand->KitLoong\\MigrationsGenerator\\{closure}()
    #14 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php(396): Illuminate\\Support\\Collection->each()
    #15 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php(345): KitLoong\\MigrationsGenerator\\MigrateGenerateCommand->generateTablesToTemp()
    #16 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php(306): KitLoong\\MigrationsGenerator\\MigrateGenerateCommand->generateSquashedMigrations()
    #17 /var/www/html/vendor/kitloong/laravel-migrations-generator/src/MigrateGenerateCommand.php(102): KitLoong\\MigrationsGenerator\\MigrateGenerateCommand->generate()
    #18 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): KitLoong\\MigrationsGenerator\\MigrateGenerateCommand->handle()
    #19 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
    #20 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
    #21 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
    #22 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Container\\BoundMethod::call()
    #23 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(144): Illuminate\\Container\\Container->call()
    #24 /var/www/html/vendor/symfony/console/Command/Command.php(308): Illuminate\\Console\\Command->execute()
    #25 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(126): Symfony\\Component\\Console\\Command\\Command->run()
    #26 /var/www/html/vendor/symfony/console/Application.php(1002): Illuminate\\Console\\Command->run()
    #27 /var/www/html/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand()
    #28 /var/www/html/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
    #29 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\\Component\\Console\\Application->run()
    #30 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(151): Illuminate\\Console\\Application->run()
    #31 /var/www/html/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
    #32 {main}
    "}
    
    
    bug 
    opened by ahmadfds 4
  • Fatal error: Uncaught ReflectionException: Class

    Fatal error: Uncaught ReflectionException: Class "config" does not exist in

    Describe the bug A clear and concise description of what the bug is. Installation was a breeze: Start installation command: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ c:\laravel-backend> composer require --dev "kitloong/laravel-migrations-generator" Active code page: 1252 Info from https://repo.packagist.org: #StandWithUkraine Using version ^6.4 for kitloong/laravel-migrations-generator ./composer.json has been updated Running composer update kitloong/laravel-migrations-generator Loading composer repositories with package information Updating dependencies Lock file operations: 7 installs, 0 updates, 0 removals

    • Locking doctrine/cache (2.2.0)
    • Locking doctrine/dbal (3.4.3)
    • Locking doctrine/deprecations (v1.0.0)
    • Locking doctrine/event-manager (1.1.2)
    • Locking kitloong/laravel-migrations-generator (v6.4.0)
    • Locking myclabs/php-enum (1.8.4)
    • Locking psr/cache (3.0.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 7 installs, 0 updates, 0 removals
    • Downloading myclabs/php-enum (1.8.4)
    • Downloading doctrine/dbal (3.4.3)
    • Downloading kitloong/laravel-migrations-generator (v6.4.0)
    • Installing doctrine/cache (2.2.0): Extracting archive
    • Installing doctrine/deprecations (v1.0.0): Extracting archive
    • Installing doctrine/event-manager (1.1.2): Extracting archive
    • Installing myclabs/php-enum (1.8.4): Extracting archive
    • Installing psr/cache (3.0.0): Extracting archive
    • Installing doctrine/dbal (3.4.3): Extracting archive
    • Installing kitloong/laravel-migrations-generator (v6.4.0): Extracting archive Generating optimized autoload files

    Illuminate\Foundation\ComposerScripts::postAutoloadDump

    INFO Discovering packages.

    kitloong/laravel-migrations-generator ....................................................................................................... DONE laravel/sail ................................................................................................................................ DONE laravel/sanctum ............................................................................................................................. DONE laravel/tinker .............................................................................................................................. DONE nesbot/carbon ............................................................................................................................... DONE nunomaduro/collision ........................................................................................................................ DONE nunomaduro/termwind ......................................................................................................................... DONE spatie/laravel-ignition ..................................................................................................................... DONE

    84 packages you are using are looking for funding. Use the composer fund command to find out more!

    @php artisan vendor:publish --tag=laravel-assets --ansi --force

    INFO No publishable resources for tag [laravel-assets].

    No security vulnerability advisories found

    END INSTALLATION ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    2, bootstrap/app.php did not have a $app->withFacades(); ro uncomment 3. ADDED: $app->register(\KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider::class); 4. ADDED DB CREDENTIALS TO: config/database.php

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3307'), ==>>>  **Changed port from 3306**
            'database' => env('DB_DATABASE', '**database name added here**'),
            'username' => env('DB_USERNAME', '**user name added here**),
            'password' => env('DB_PASSWORD', '**password added here**'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],
    
    1. Run php artisan migrate:generate ...
    2. See error

    Fatal error: Uncaught ReflectionException: Class "config" does not exist in C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php:875
    Stack trace: #0 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(875): ReflectionClass->__construct('config') #1 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(756): Illuminate\Container\Container->build('config') #2 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(857): Illuminate\Container\Container->resolve('config', Array, true) #3 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(692): Illuminate\Foundation\Application->resolve('config', Array) #4 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(842): Illuminate\Container\Container->make('config', Array) #5 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(98): Illuminate\Foundation\Application->make('config')
    #6 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(46): KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider->registerConfig() PS C:\laravel-backend> php artisan migrate:generate

    Fatal error: Uncaught ReflectionException: Class "config" does not exist in C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php:875
    Stack trace: #0 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(875): ReflectionClass->__construct('config') #1 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(756): Illuminate\Container\Container->build('config') #2 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(857): Illuminate\Container\Container->resolve('config', Array, true) #3 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(692): Illuminate\Foundation\Application->resolve('config', Array) #4 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(842): Illuminate\Container\Container->make('config', Array) #5 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(98): Illuminate\Foundation\Application->make('config')
    #6 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(46): KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider->registerConfig() #7 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(686): KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider->register()#8 C:\laravel-backend\bootstrap\app.php(45): Illuminate\Foundation\Application->register(Object(KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider)) #9 C:\laravel-backend\artisan(20): require_once('D:\Dev\limber\A...') #10 {main}

    Next Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist. in C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php:877 Stack trace: #0 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(756): Illuminate\Container\Container->build('config') #1 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(857): Illuminate\Container\Container->resolve('config', Array, true) #2 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php(692): Illuminate\Foundation\Application->resolve('config', Array) #3 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(842): Illuminate\Container\Container->make('config', Array) #4 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(98): Illuminate\Foundation\Application->make('config')
    #5 C:\laravel-backend\vendor\kitloong\laravel-migrations-generator\src\MigrationsGeneratorServiceProvider.php(46): KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider->registerConfig() #6 C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(686): KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider->register()#7 C:\laravel-backend\bootstrap\app.php(45): Illuminate\Foundation\Application->register(Object(KitLoong\MigrationsGenerator\MigrationsGeneratorServiceProvider)) #8 C:\laravel-backend\artisan(20): require_once('D:\Dev\limber\A...') #9 {main} thrown in C:\laravel-backend\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 877

    Details (please complete the following information):

    • DB: [e.g. MariaDB]
    • DB Version: [e.g. 10.6.5]
    • Laravel Version: ^9
    • PHP Version: 8.0.13
    • Migrations Generator Version: UNKNOWN

    Additional context It does not matter which artisan command I run I continue to get the error message as above e.g. php artisan serve give the error above and so does an artisan command

    How to roll back?

    opened by Prem-Limber 4
  • Generate migrations with custom column type

    Generate migrations with custom column type

    Fixes #65 and #75

    How it works

    This feature is dedicated to PostgreSQL v10 and above. See https://www.postgresql.org/docs/current/sql-createtype.html

    The generator will register custom data type from pg_type, then generate migration as

    public function up()
    {
        Schema::create('table', function (Blueprint $table) {
            ...
        });
        DB::statement("ALTER TABLE table ADD column custom_type NOT NULL");
    }
    

    !! Note

    Note that the new column is always appended after the table is created which means the ordering of the column generated from migration will differ from what we have from the schema.

    opened by kitloong 4
  • error trying to use the package

    error trying to use the package

    I got this error after executed the package

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'LEVEL' in 'where clause' (SQL: SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE TABLE_NAME = 'failed_jobs' AND CONSTRAINT_SCHEMA = 'staging_scanner' AND LEVEL = 'Column' AND CHECK_CLAUSE LIKE '%json_valid(payload)%')

    bug 
    opened by matiazar 4
  • Primary key column small bug 🤔

    Primary key column small bug 🤔

    Hi, thanks for your work 👏

    I think I found a little bug. It is about generating an entry for the column from the primary key. Currently, the following line is generated: $table-> integer ('Id', true);

    And according to the documentation https://laravel.com/docs/9.x/migrations#column-method-bigIncrements should be generated like this: $table -> bigIncrements ('id'); or $table -> id(); in conjunction with this link https://laravel.com/docs/9.x/migrations#column-method-id

    Thank you again for your work 👍

    opened by everstudybee 4
  • Fatal throwable error on generate

    Fatal throwable error on generate

    Hi, I'm on laravel 6 and after installing the package with composer and running php artisan migrate:generate i get this error Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to MigrationsGenerator\MigrationsGeneratorSetting::setTableFilename() must be of the type string, null given, called in C:\lar agon\www\erp\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\MigrateGenerateCommand.php on line 116

    needs more info 
    opened by rafiktoumi 4
  • Timestamps problem

    Timestamps problem

    • users table
    CREATE TABLE `users`  (
      `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
      `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '姓名1,
      `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
      `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
    
    • exec generate
    $ php artisan migrate:generate users
    
    • migration file
    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateUsersTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('users', function (Blueprint $table) {
                $table->increments('id')->comment('ID');
                $table->timestamps()->comment('更新时间');
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('users');
        }
    }
    

    $table->timestamps()->comment('更新时间');This line raises an error while performing the migration.Because it has no comment method.Hope you can help, thank you very much!

    opened by yuhal 4
  • PostgreSQL add migration to create domains

    PostgreSQL add migration to create domains

    Imagine this scenario in a PostgreSQL db:

    1. Create a domain: create domain word64 as varchar(64);
    2. Create the following table:
    CREATE TABLE cars (
      id serial PRIMARY KEY,
      name word64 NOT null
    );
    
    1. Run the command: php artisan migrate:generate

    2. Migration created:

    Schema::create('cars', function (Blueprint $table) {
      $table->increments('id');
    });
    DB::statement("ALTER TABLE cars ADD name word64 NOT NULL");
    

    Obviously if you try to execute this migration you will get an error cause postgres can't recognize the word64 type. I would like that the command php artisan migrate:generate generate another migration to specify the domains created previously.

    enhancement 
    opened by EmptySpace99 1
Releases(v6.7.1)
Owner
Kit Loong
Kit Loong
Automatically generate ERD Diagrams from Model's relations in Laravel

Laravel ERD Generator Automatically generate interactive ERD from Models relationships in Laravel. This package provides a CLI to automatically genera

Pulkit Kathuria 90 Dec 29, 2022
Laravel MiGator - Migrations Generator

Laravel Migator A package that will allow developers to interactively generate schema migrations for a laravel application. It takes into account the

Synetic 2 Oct 13, 2022
Laravel messenger. A full messenger suite for your new / existing laravel app

Laravel messenger. A full messenger suite for your new / existing laravel app! Private and group threads between multiple models, with real-time messaging, reactions, attachments, calling, chat bots, and more!

Richard  Tippin 290 Dec 30, 2022
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Munaf Aqeel Mahdi 1.7k Jan 5, 2023
Automatically load your helpers in your laravel application.

Laravel AutoHelpers Automatically load your helpers in your laravel application. Installation You can install the package via composer: composer requi

Florian Wartner 6 Jul 26, 2021
Declare database migrations and factory definitions inside Laravel models.

Lucid This package allows you to declare database migrations and factory definitions inside of your Laravel models. Running the lucid:migrate command

null 23 Jul 9, 2022
Generate trends for your models. Easily generate charts or reports.

Laravel Trend Generate trends for your models. Easily generate charts or reports. Support us Like our work? You can support us by purchasing one of ou

Flowframe 139 Dec 27, 2022
Validate PHP database migration files for compliance with best practices. Ensure db migrations are irreversible.

PHP DB Migration Validator Introduction In modern PHP frameworks such as Symfony and Laravel, migrations usually have up and down methods. In up metho

Anton Komarev 17 Dec 14, 2022
Laravel Design Pattern Generator (api generator)

Laravel Design Pattern Generator (api generator) you can create your restful api easily by using this library and you can filter, sort and include elo

HusseinAlaa 2 Sep 25, 2022
Laravel generator with GUI. Generate crud / scaffold.

Laravel generator with GUI. Generate crud / scaffold.

George 420 Dec 5, 2022
Is an Extension of Laravel View Class which compiles String Template on the fly. It automatically detects changes on your string template and recompiles it if needed.

Laravel-fly-view Is an Extension of Laravel View Class which compiles String Template on the fly. It automatically detects changes on your string temp

John Turingan 16 Jul 17, 2022
Package to optimize your site automatically which results in a 35%+ optimization

Laravel Page Speed Simple package to minify HTML output on demand which results in a 35%+ optimization. Laravel Page Speed was created by Renato Marin

Renato Marinho 2.2k Dec 28, 2022
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 28 Dec 19, 2022
Easily add all the 58 Algerian Wilayas and its Dairas to your cool Laravel project (Migrations, Seeders and Models).

Laravel-Algereography Laravel-Algereography allows you to add Migrations, Seeders and Models of Algerian Wilayas and Dairas to your existing or new co

Hocine Saad 48 Nov 25, 2022
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 955 Dec 25, 2022
Automatically disable Google's FLoC in Laravel apps

Automatically disable Google's FLoC in Laravel apps This package will automatically disable Google's FLoC. Support us We invest a lot of resources int

Spatie 68 Oct 21, 2022
Automatically encrypt and decrypt Laravel 5 Eloquent values

Eloquent Encryption/Decryption for Laravel 5 Automatically encrypt and decrypt Laravel 5 Eloquent values. READ THIS FIRST Encrypted values are usually

Del 85 Mar 19, 2022
Searches for multilingual phrases in Laravel project and automatically generates language files for you.

Laravel Lang Generator Searches for multilingual phrases in a Laravel project and automatically generates language files for you. You can search for n

Gleb 5 Oct 19, 2022
Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude

Laravel Addresses Simple address and contact management for Laravel with automatically geocoding to add longitude and latitude. Installation Require t

Chantouch Sek 2 Apr 4, 2022