thinkphpÐÞ¸Ä×Ö¶Î
Ëæ×Åweb¿ª·¢ÊÖÒÕµÄһֱǰ½ø£¬¿ò¼ÜÊÖÒÕÔ½À´Ô½³ÉÊ죬thinkphp×÷Ϊһ¿î¿ªÔ´µÄphp¿ª·¢¿ò¼Ü£¬ÔÚ¿ª·¢ÁìÓòÈ¡µÃÁ˲»´íµÄÊг¡·Ý¶î¡£ÔÚʹÓÃthinkphp¿ª·¢ÏîĿʱ£¬¾³£ÐèÒª¶ÔÊý¾Ý¿âÖеÄ×ֶξÙÐÐÐ޸ġ£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp¾ÙÐÐ×ֶεÄÐ޸ġ£
Ò»¡¢ÔÚThinkPHPÖÐÐÞ¸Ä×ֶεÄÒªÁì
1.ʹÓÃMigration
ThinkPHPÖеÄMigration¿ÉÒÔ×ÊÖúÎÒÃǾÙÐÐÊý¾Ý¿âǨá㣬°üÀ¨½¨Éè±í¡¢É¾³ý±í¡¢Ìí¼Ó×ֶΡ¢ÐÞ¸Ä×ֶεȲÙ×÷¡£ÔÚ¾ÙÐÐ×ֶεÄÐÞ¸Äʱ£¬ÎÒÃÇÊ×ÏÈÐèÒªÌìÉúMigrationµÄÎļþ¡£ÔÚÏÂÁîÐÐÖÐʹÓÃÈçÏÂÏÂÁîÌìÉúMigrationÎļþ£º
php think make:migration alter_table_field
µÇ¼ºó¸´ÖÆ
´Ëʱ£¬ThinkPHP½«ÔÚÓ¦ÓÃĿ¼µÄdatabase/migrations/Ŀ¼ÏÂÌìÉúÒ»¸öÃûΪ20210101010101_alter_table_field.phpµÄPHPÎļþ¡£ÔÚ¸ÃÎļþÖУ¬ÎÒÃÇÐèÒª±àдÐÞ¸Ä×ֶεIJÙ×÷¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
2.ÐÞ¸ÄMigrationÎļþ
ÐÞ¸ÄMigrationÎļþµÄ·½·¨ÈçÏ£º
£¨1£©ÔÚup()ÒªÁìÖÐŲÓÃSchema::table()ÒªÁ죬ָ¶¨ÐèÒªÐÞ¸Ä×ֶεıíÃû£¬È磺
Schema::table('user', function (Blueprint $table) { // });
µÇ¼ºó¸´ÖÆ
£¨2£©ÔÚSchema::table()ÒªÁìÖУ¬Ê¹ÓÃ$table->xxx()ÒªÁìÐÞ¸Ä×ֶΡ£ÀýÈ磬½«name×ֶθÄΪusername£¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺
Schema::table('user', function (Blueprint $table) { $table->renameColumn('name', 'username'); });
µÇ¼ºó¸´ÖÆ
£¨3£©ÔÚdown()ÒªÁìÖбàд»Ø¹ö²Ù×÷¡£ÀýÈ磬½«username×ֶλعöΪname×ֶΣ¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺
Schema::table('user', function (Blueprint $table) { $table->renameColumn('username', 'name'); });
µÇ¼ºó¸´ÖÆ
3.Ö´ÐÐMigration
ÐÞ¸ÄMigrationÎļþºó£¬ÐèÒªÖ´ÐÐMigration¾ÙÐÐÊý¾Ý¿âǨáã¡£ÔÚÏÂÁîÐÐÖÐʹÓÃÈçÏÂÏÂÁîÖ´ÐÐMigration£º
php think migrate
µÇ¼ºó¸´ÖÆ
´Ëʱ£¬ThinkPHP½«ÒÀ´ÎÖ´ÐÐËùÓÐδִÐйýµÄMigrationÎļþÖеIJÙ×÷¡£
¶þ¡¢×¢ÖØÊÂÏî
1.ÐÞ¸Ä×Ö¶ÎʱӦעÖØ×Ö¶ÎÀàÐ͵ļæÈÝÐÔ£¬ÀýÈç²»¿É½«ÕûÐÍ×ֶθÄΪ×Ö·ûÐÍ×ֶΡ£
2.ÐÞ¸Ä×Ö¶ÎʱӦעÖØÊý¾ÝµÄ¼æÈÝÐÔ£¬ÀýÈçÈôÐÞ¸Ä×Ö·ûÐÍ×ֶεij¤¶È£¬Ó¦È·±£Ð޸ĺóµÄ³¤¶È×ã¹»´æ´¢ÒÑÓÐÊý¾Ý¡£
3.ÔÚÐÞ¸Ä×Ö¶ÎʱӦעÖرíÖÐÊÇ·ñ±£´æ¸Ã×ֶΣ¬Èô²»±£´æÓ¦ÏÈÌí¼Ó×ֶκóÔÙ¾ÙÐÐÐ޸ġ£
Èý¡¢×ܽá
ÔÚʹÓÃThinkPHP¿ª·¢ÏîĿʱ£¬ÓÉÓÚÐèÇóµÄת±ä»òÕßÆäËûÔµ¹ÊÔÓÉ£¬¿ÉÄÜÐèÒª¶ÔÊý¾Ý¿âÖеÄ×ֶξÙÐÐÐ޸ġ£±¾ÎÄÏÈÈÝÁËʹÓÃThinkPHPµÄMigration¾ÙÐÐ×Ö¶ÎÐ޸ĵÄÒªÁ죬ͬʱҲÌáÐÑÁËÔÚÐÞ¸Ä×Ö¶ÎʱÐèҪעÖصÄÊÂÏϣÍû±¾ÎÄÄÜ×ÊÖú¶ÁÕ߸üºÃµØʹÓÃThinkPHP¾ÙÐпª·¢¡£
ÒÔÉϾÍÊÇthinkphpÐÞ¸Ä×ֶεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡