Yii2 migrations. Percentage sign and brackets in table name

一曲冷凌霜 提交于 2019-12-14 03:58:02

问题


I browsed the yii2-oauth2-server code on github and encountered interesting syntax in the migration file. The code in question looks like this:

    $this->createTable('{{%oauth_clients}}', [
        ...
    ], $tableOptions);

Can someone explain the {{%oauth_clients}} part? What does it mean when the table name is enclosed in {{%..}}? The official documentation on migrations says nothing about it and all examples have the "raw" table names like this:

    $this->createTable('post_tag', [
        ...
    ]);

I checked my database and the table was created as if there were no brackets, its name is simply oauth_clients.


回答1:


Is used for table prefix

From yii2 documentation on Db connection:

If a table name is given as {{%TableName}}, then the percentage character % will be replaced with this property value. For example, {{%post}} becomes {{tbl_post}}.



来源:https://stackoverflow.com/questions/38698129/yii2-migrations-percentage-sign-and-brackets-in-table-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!