Search code examples
mysqllaravelmysql-workbenchseeding

Inserting data from SQL to Laravel seed file


I have several pre-populated tables in MySQL Workbench, and I desire to move the data from those tables into the tables, I created using migrations in Laravel. I read that you use seed files to insert data but the documentation doesn't really go over this aspect.

E.G.: one of my tables in SQL looks like: id | course 1 | CHEMISTRY 101 2 | BIOLOGY 101 3 | ENGINEERING 101 //etc

Now this is defined in SQL, but I would like to move this data into my migration/seed file for my courses table. How would I go about doing this an easy and fast way, without having to manually enter data?


Solution

  • If you are using MySQL Workbench you can export the data.

    Use [the] wizard to either export or import SQL generated from MySQL Workbench or with the mysqldump command.

    This will create detailed database and table operations, standard backup/restore behavior using the mysqldump command and meta data, includes control over how data is handled, and includes meta data