Laravel: Import Old Database from SQL Dump Without Migrations

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys today I want to quickly discuss the situation where you have an old database exported to you in SQL format and you need to import that into a laravel project so create laravel database from an older MySQL for example database so imagine this table I took it from stack Overflow randomly so you have all those create table statements and maybe other statements for other tables and you need to work with laravel to recreate that project and what I want to emphasize here is your first impression would be first feeling to create the migration from that try to go field by field and create table string this table Boolean that but this is not the only way to do that there are packages to generate migrations from your database from your SQL but they are not 100 reliable why because it's impossible to accurately guess which field type corresponds to which migration method in laravel in some cases it's not even possible to match because SQL field was created with different logic than laravel provides so what I wanted to say here is that you can just run database statement without any migrations if you have a laravel project and you want to perform laravel and eloquent operations you don't necessarily have to have migrations so for example you can do DB statement and paste all of that creatable as is without any migrations I mean it is a migration there is up method and you would still run PHP artists on Migrate but there's no schema table or schema create as you would do in a new migration and if you have multiple tables it's not even necessary to paste that in the migration another even quicker way is this you have SQL dump as usual from someone and you can dump it in just by running DB unprepared and this method would get the contents of that file file as a string and would run pretty much the same thing as I've shown in a previous example this comes by the way from repository laravel tips on GitHub it's free for you there are hundreds of tips I have gathered over the years of laravel career from myself and other people so I will link that in the description below as well so I just wanted to emphasize that it's not necessary to have migrations but warning keep in mind that if you proceed this way some of the eloquent functions will not work as intended for example if ID patient it's not in a typical laravel format it's not ID then you need to specify that in eloquent model if it's not Auto increment then inserting new records may not work as intended if you have a new table that could have a foreign key to this you would need to get around that not being unsigned for example it should be unsigned big integer by default in laravel so stuff like that you should be careful that something may not work if you have older database and this is of course solved only manually no one would guess for you what that old database contains but if you just have SQL dump you want to put it in your laravel project just put it as is without any migration functions of laravel what do you think about this approach have you done that in the past such bulk import let's discuss in the comments below and see you guys in other videos
Info
Channel: Laravel Daily
Views: 9,106
Rating: undefined out of 5
Keywords:
Id: B5KpKyyaugc
Channel Id: undefined
Length: 3min 23sec (203 seconds)
Published: Sun Aug 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.