- Required
Laravel
Database migration function, because I am a Virgo with obsessive-compulsive disorder, so I like to name the files myself. For example:
But when executing the migration error:
After several rounds of attempts, I found that Laravel
- File name naming format for migration files
- has a fixed parsing, so when I write the file name exactly according to its style, it will run normally
Of course the class name It must also be unified:
The point of complaint is: The document does not mention the mandatory requirements for file name naming style
Therefore Recording this pitfall today- seems to be another pitfall or a shortcoming of the framework: that is, the table structure
cannot be continuously integrated
. For example, today I need to add fields to a certain table. But it has been migrated at this time, then There is no way to run the same migration file again and a new migration file must be created - . Of course, I also understand that this is to facilitate rollback, but my requirement is Continuously adding fields for new functions does not require rollback, so my
solution
is to clearmigrations
this table every time, because this table controls whether it can be repeated Where the same migration file is run, the code is as follows:trait Trait_Migrate { /** * @desc 数据表:初始化 * @return Void */ static public function CI_Table_Structure() : Void { # 清空记录表以保证能持续迁移 DB::table( 'migrations' ) -> truncate(); # 执行迁移 Artisan::call( 'migrate --force --path=/database/migrations/' . SELF::$CI_File ); } }
Generally speaking, it will be smooth sailing if you follow the rules of the framework document completely. However, when doing projects, the default functions of the framework cannot meet the needs. The situation is very normal
- Related recommendations: