skip to Main Content

Im new to laravel, someone asked me to modify in his project, these modifications need to have new tables, I created tables directly on phpmyadmin, these tables include countries and regions tables which have huge rows, I wanted to push the project to the server but don’t have access to the database so must using migrate, my questions are:

  • how can I migrate the tables I created in phpmyadmin? I didnt create tables using the command artisan migrate.

  • how can I push countries and regions tables contents?
    thank you in advance

3

Answers


  1. This is not a correct approach, If you are using Laravel and manually uploading the data.

    The better solution is to write the migrations and seeder.

    You can print db result in an array and paste everything in your Seeder file, Check the syntax on Laravel website

    Login or Signup to reply.
  2. Firstly familarise yourself with the documentation on Laravel Migrations (https://laravel.com/docs/6.x/migrations). The documenation is excellent!

    If you want to replicate the structure of the table you have already created, I would start by getting the table schema from phpmyadmin and then simply walking through it line by line and finding the appropriate methods in the documentation.

    Once you have matched the table structure, it then just a case of taking a database dump of your existing table and importing it.

    Login or Signup to reply.
  3. To update the production server database you still can use migrations, even if you created tables manually on local environment.

    Please read the docs for more info.

    Run the command: php artisan make:migration table-name in local environment, and write required columns in created file.

    After that, you can upload this file on the server and just run: php artisan migrate this will create tables on the prod database.


    To automatically insert data after migrations you can use seeding: https://laravel.com/docs/5.7/seeding

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search