尊龙凯时人生就是博

ThinkPHP6ÖÐÔõÑùʹÓÃPhinx¾ÙÐÐÊý¾Ý¿âǨá㣿

Ëæ×ÅwebÓ¦ÓóÌÐòµÄѸÃÍÉú³¤ £¬Êý¾Ý¿â×÷ΪӦÓóÌÐòµÄÒ»²¿·Ö £¬Ò²±»¸¶ÓëÁ˸ü¸ßµÄÖ÷ÒªÐÔ ¡£¹ØÓÚweb¿ª·¢ÕßÀ´Ëµ £¬Êý¾Ý¿âÊý¾ÝµÄÇå¾²ÐÔ¡¢¿É¿¿ÐÔºÍÎȹÌÐÔ¶¼ÊÇÖÁ¹ØÖ÷ÒªµÄ ¡£Êý¾Ý±íµÄÉè¼ÆºÍÖÎÀíÒ²ÊÇ¿ª·¢ÊÂÇéµÄÒªº¦²¿·Ö £¬Òò´ËÊý¾ÝǨáã³ÉΪÊý¾Ý¿â²Ù×÷µÄÖ÷ÒªÒªÁìÖ®Ò» ¡£

PhinxÊÇÒ»¸öPHP¿â £¬Ëü¿ÉÒÔ×ÊÖú¿ª·¢Ö°Ô±¶ÔÓ¦ÓóÌÐò¾ÙÐÐÊý¾Ý¿âǨáãºÍÖÎÀí ¡£¶øThinkPHP6×÷Ϊһ¸öÊ¢ÐеÄPHP¿ò¼Ü £¬Ò²ÌṩÁËPhinxµÄʹÓÃÒªÁì £¬¿ÉÒÔ¼ò»¯ÎÒÃǵĿª·¢ÊÂÇé ¡£

±¾ÎĽ«ÏÈÈÝThinkPHP6¿ò¼ÜÖÐʹÓÃPhinx¾ÙÐÐÊý¾Ý¿âǨáãµÄÒªÁì ¡£

×°ÖÃPhinx

ÏÈÔÚÏîĿĿ¼ÏÂʹÓÃComposer×°ÖÃPhinx£º

composer require robmorgan/phinx

µÇ¼ºó¸´ÖÆ

ÉèÖÃPhinx

ÔÚThinkPHP6ÖÐ £¬PhinxµÄÉèÖÃÔÚconfig/phinx.phpÎļþÖÐ ¡£¿ÉÒÔͨ¹ýÏÂÁîÐй¤¾ßÌìÉúĬÈÏÉèÖÃÎļþ£º

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

vendor/bin/phinx init

µÇ¼ºó¸´ÖÆ

Ö´ÐÐÍê±Ïºó £¬configĿ¼Ï»áÌìÉúphinx.phpÎļþ ¡£ÎÒÃÇÐèÒªÔÚÆäÖÐÉèÖÃÊý¾Ý¿âµÄÅþÁ¬ÐÅÏ¢ºÍĿ¼½á¹¹µÈÐÅÏ¢ ¡£

ÀýÈç £¬ÉèÖÃÊý¾Ý¿âÅþÁ¬ÐÅÏ¢£º

return [
    'paths' => [
        'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
        'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
    ],
    'environments' => [
        'default_database' => 'development',
        'development' => [
            'adapter' => 'mysql',
            'host' => '127.0.0.1',
            'name' => 'thinkphp6',
            'user' => 'root',
            'pass' => '123456',
            'charset' => 'utf8',
        ]
    ]
];

µÇ¼ºó¸´ÖÆ

½¨ÉèÊý¾Ý¿âǨáã

ÔÚThinkPHP6ÖÐ £¬PhinxµÄÊý¾Ý¿âǨáã´æ´¢ÔÚdatabase/migrationsĿ¼ÖÐ ¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁÉèÒ»¸öеÄǨá㣺

vendor/bin/phinx create MyNewMigration

µÇ¼ºó¸´ÖÆ

Ö´ÐиÃÏÂÁîºó»áÔÚdatabase/migrationsĿ¼Ï½¨ÉèÒ»¸öеÄǨáãÎļþ ¡£

ÔÚPhinxÖÐ £¬Ç¨áã·ÖΪÁ½ÖÖÀàÐÍ£ºÇ¨áãºÍ»Ø¹ö ¡£Ç¨áã°üÀ¨¶ÔÊý¾Ý¿âµÄ¸ü¸Ä £¬»Ø¹öÖ´ÐÐÓëǨáãÏà·´µÄ²Ù×÷ ¡£

ºÃ±È £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öusers±í£º

use PhinxMigrationAbstractMigration;

class CreateUsersTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * More information on this method is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-change-method
     */
    public function change()
    {
        $table = $this->table('users');
        $table->addColumn('username', 'string', ['limit' => 50])
              ->addColumn('email', 'string', ['limit' => 100])
              ->addColumn('password', 'string', ['limit' => 255])
              ->addColumn('created_at', 'datetime')
              ->addColumn('updated_at', 'datetime')
              ->create();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚchange()ÒªÁìÖÐ £¬Ê¹ÓÃ$table±äÁ¿¹¹½¨±í½á¹¹ £¬²¢Ê¹ÓÃaddColumn()ÒªÁìΪ²î±ðµÄÁÐÖ¸¶¨Ãü¾ÝÀàÐͺÍÏÞÖÆ ¡£×îºóŲÓÃcreate()ÒªÁì £¬½«±í½á¹¹½¨Éèµ½Êý¾Ý¿âÖÐ ¡£

Ö´ÐÐÊý¾Ý¿âǨáã

ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÖ´ÐÐǨá㣺

vendor/bin/phinx migrate

µÇ¼ºó¸´ÖÆ

Phinx»áƾ֤½¨ÉèǨáãµÄÏȺó˳ÐòÖ´Ðиü¸Ä ¡£ÈôÊÇËùÓÐǨáãÖ´ÐÐÀÖ³É £¬Phinx½«»áÔÚÊý¾Ý¿âÖн¨ÉèÒ»¸öÃûΪphinxlogµÄ±íÒԼͼǨáãÀúÊ· ¡£

×¢ÖØ£ºÖ´ÐÐǨá㽫»á¶ÔÊý¾Ý¿â¾ÙÐиü¸Ä £¬ÇëÈ·±£±¸·ÝÊý¾Ý £¬ÒÔ·ÀÊý¾Ýɥʧ»òÎÞ·¨»Ö¸´ ¡£

»Ø¹öÊý¾Ý¿âǨáã

ÈôÊÇ·ºÆð¹ýʧ»òÐèÒª»ØÍ˸ü¸Ä £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî»ØÍËÉÏÒ»´ÎǨá㣺

vendor/bin/phinx rollback

µÇ¼ºó¸´ÖÆ

Phinx»á»Ø¹öÉÏÒ»´ÎÀÖ³ÉÖ´ÐеÄǨá㣨ÈôÊDZ£´æ£© ¡£Phinx»áÔڻعöǨáãºó½«ÐÅϢдÈëµ½phinxlog±íÖÐ ¡£

×ܽá

ÒÔÉϾÍÊÇÔÚThinkPHP6ÖÐʹÓÃPhinx¾ÙÐÐÊý¾Ý¿âǨáãµÄÀú³Ì ¡£Ê¹ÓÃPhinx¿ÉÒÔïÔÌ­ÊÖдSQLµÄÖØ´óÐÔºÍΣº¦ £¬Ê¹Êý¾Ý¿âǨáãÀú³ÌÔ½·¢ÇáÓ¯ºÍ¿É¿Ø ¡£

ÔÚǨáãÀú³ÌÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃPhinxµÄ¸ß¼¶¹¦Ð§ £¬ÀýÈçÊý¾ÝÌî³ä¡¢Êý¾ÝУÑéºÍÖ§³Ö´ó¶¼¾Ý¿â ¡£ÕâЩ¹¦Ð§¿ÉÒÔ´ó´óÌá¸ßÓ¦ÓóÌÐòµÄ¿Éά»¤ÐÔºÍÐÔÄÜ ¡£

ÔÚÏÖʵ¿ª·¢ÖÐ £¬ÎÒÃǽ¨Ò齫Êý¾Ý¿âǨáãºÍÖÎÀí×÷ΪÍŶӿª·¢µÄÒ»²¿·Ö £¬ÒÔÈ·±£Êý¾Ý½á¹¹µÄÒ»ÖÂÐԺͿɿ¿ÐÔ ¡£

ÒÔÉϾÍÊÇThinkPHP6ÖÐÔõÑùʹÓÃPhinx¾ÙÐÐÊý¾Ý¿âǨá㣿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ