Answer the question
In order to leave comments, you need to log in
How to properly work with yii2 database?
Hello!
I recently started my acquaintance with YII2, I would like to ask a question to an experienced database developer. I want to make my own test application, installed the advanced template, applied the standard migration. Uploaded everything to git. Created a user through the yii web interface.
I am developing on two different computers, respectively, on one I uploaded the changes to the git server, on the second I downloaded. Applied migrations - I can continue to work. As far as I understand, migrations describe the structure of the database, but do not work with data (I haven’t figured it out yet). But what about the data? Here I created the user on one computer essentially manually, on the second I also created it manually? Those. on one computer in mysql there is information about the user in the database, but not on the second. Perhaps there is some convenient means so that the data in the database is also synchronized? Or do you just need to merge the SQL dump, and then apply it manually?
How is the work with the database generally carried out when the development team is working? Does everyone have their own data in the database? And when is it already uploaded to the test server and filled in the database with the necessary information?
Answer the question
In order to leave comments, you need to log in
It would be better to describe what specific problem you are trying to solve.
If the task is to create records when creating a database (for example, a default user), then insert can be used in migrations, for example:
public function up()
{
$this->createTable('{{%mymodel}}', [
'id' => $this->primaryKey(),
'name' => $this->string(128)->notNull(),
], 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB');
$this->insert('{{%mymodel}}', [
'name' => 'modelName',
]);
$this->insert('{{%mymodel}}', [
'name' => 'anotherModelName',
]);
}
If the data will be used on all servers, then the filling can also be added to the migration.
If this is temporary data, use it as a dump from INSERT.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question