L
L
Lomoson2015-03-03 17:19:07
Yii
Lomoson, 2015-03-03 17:19:07

How to automatically generate table schema in Yii2/migrate?

Can you please tell me how to automatically generate the following code:

$this->createTable('{{%users}}', [
            'id'            => Schema::TYPE_PK,
            'username'      => Schema::TYPE_STRING . '(25) NOT NULL',
            'email'         => Schema::TYPE_STRING . '(255) NOT NULL',
], $tableOptions);

yii migrate/create users table_name
does not create a schema.
I have > 50 tables, which are interconnected and manually write for a long time and can be closed.
And please tell me how to properly write:
ALTER TABLE `users`
  ADD CONSTRAINT `users_news` FOREIGN KEY (`user_ID`) REFERENCES `users` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
phpnt, 2015-03-06
@phpnt

Using migrations in Yii2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question