A
A
Anton2016-07-15 13:35:54
Yii
Anton, 2016-07-15 13:35:54

How to add tables of cities, countries and regions by migration?

Hello, I found such a database in the form of sql and now I need to add it by migration, how can I do it not manually?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kim, 2016-07-15
Reytarovsky @Antonchik

If the sql-base is already ready and you just need to fill it in, then here is the option:

  • in the up method write:
  • $this->db->createCommand(file_get_contents('console/migrations/sqls/cities.sql'))->execute();

    M
    Maxim Timofeev, 2016-07-15
    @webinar

    If in the form of sql - then it's easier to go to phpMyAdmin and import. Why migrations? Migrations are convenient in terms of creating a table.
    But filling from the sql file is not very good.
    Here are the docs:
    www.yiiframework.com/doc-2.0/guide-db-migrations.h...
    Here you will have to parse your sql file, sort through the array through foreach and form the syntax necessary for migrations. So it's possible of course, but why?

    Didn't find what you were looking for?

    Ask your question

    Ask a Question

    731 491 924 answers to any question