-2

Currently I am using this code to add a user in db

Yii2-user: How to create a user in batch mode

But I would like to add more than one user using migrations.

1 Answers1

1

If you want to create a certain amount of users in one migration, then there is no problem, you can place the given code in a loop in duplicate the code with different params.

However if you want to use multiple migrations for multiple users, then it is a very bad idea. In fact migrations are mainly used to change the database structure DDL, and less often for DML manipulations. And here row changes are related to system functionality (for instance permissions), not to data like Users (that can differ on different instances of application)

Shortly, you should know what "migrations" are used for. You can get information about migrations in the official Yii documentation:
Yii2 Database migration

In case you want to add "instance" related data, then I suggest you to use user creation code in Controllers. Console controller should fit needs. Information about console controllers you can get here:
Yii2. Creating your own console commands

Yerke
  • 2,187
  • 3
  • 19
  • 33