Can I import a mysql dump to a laravel migration?

后端 未结 10 1885
离开以前
离开以前 2020-12-24 11:46

I have a complete database and need to create migration. I guess there must be a way to do it from a dump but not sure. Is there any way automatically or at least easier to

相关标签:
10条回答
  • 2020-12-24 12:07

    i recently standing in front of the same problem. i didn't want to install a package specially for that, so i decided to write a little tool to help me and others ;)

    Here is the link: http://laravel.stonelab.ch/sql-seeder-converter/

    And here you can comment it, if you have any improvement proposals or questions: http://www.stonelab.ch/en/sql-to-laravel-seeder-converter/

    0 讨论(0)
  • 2020-12-24 12:16

    Laravel can't do that, but I think this will help: Laravel migration generator

    It generate migrations based on existing tables.

    0 讨论(0)
  • 2020-12-24 12:20

    You can create laravel migration and models directly from database using https://github.com/XCMer/larry-four-generator

    Execute the following code after installing the package

    php artisan larry:fromdb
    
    0 讨论(0)
  • 2020-12-24 12:26

    You can import dumps in Laravel like this:

    DB::unprepared(file_get_contents('full/path/to/dump.sql'));
    

    If I were to refactor an existing app, though, I'd take the time to write migrations from scratch, import the dump into different tables (or a different db, if table names are the same) then import the content to the new structure via seeds.

    0 讨论(0)
提交回复
热议问题