尊龙凯时人生就是搏

laravel ÌáÐÑûÓÐÖ÷¼ü

ÔÚʹÓà laravel ¾ÙÐÐÊý¾Ý¿â²Ù×÷ʱ£¬ÓÐʱ¼ä»áÓöµ½Ò»¸ö³£¼ûµÄÎÊÌ⣺ûÓÐÖ÷¼ü¡£ÕâÊÇÓÉÓÚÔÚ laravel ĬÈϵÄÄ£×ÓÖУ¬»á×Ô¶¯¼Ù¶¨Ö÷¼üΪ id£¬ÈôÊÇÊý¾Ý¿âÖÐûÓÐ id ×ֶλòÕ߸Ã×Ö¶ÎûÓб»ÉèÖÃΪÖ÷¼ü£¬¾Í»áÌáÐÑûÓÐÖ÷¼üµÄ¹ýʧ¡£

ÄÇô£¬ÔõÑù½â¾öûÓÐÖ÷¼üµÄÎÊÌâÄØ£¿ÏÂÃ潫»®·Ö´ÓÊý¾Ý¿âºÍ Laravel Ä£×ӵĽǶÈÀ´ÏÈÈݽâ¾öÒªÁì¡£

Ò»¡¢Êý¾Ý¿â½â¾öÒªÁì

ÉèÖÃÖ÷¼ü

ÔÚ MySQL Êý¾Ý¿âÖУ¬¿ÉÒÔʹÓà ALTER TABLE Óï¾äÀ´Ð޸ıíµÄ½á¹¹£¬°üÀ¨ÉèÖÃÖ÷¼ü¡£Àý£º

ALTER TABLE ±íÃû ADD PRIMARY KEY(×Ö¶ÎÃû);

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬±íÃûºÍ×Ö¶ÎÃûÐèÒª×ÔÐÐÌæ»»¡£

½¨ÉèеÄÖ÷¼ü

ÈôÊÇÊý¾Ý¿âÖÐûÓÐÊʺϵÄÖ÷¼ü×ֶΣ¬¿ÉÒÔͨ¹ýн¨Ò»¸öÖ÷¼ü×Ö¶ÎÀ´½â¾öÎÊÌâ¡£Àý£º

ALTER TABLE ±íÃû ADD ×Ö¶ÎÃû INT AUTO_INCREMENT PRIMARY KEY;

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬±íÃûºÍ×Ö¶ÎÃûÐèÒª×ÔÐÐÌæ»»¡£AUTO_INCREMENT ÌåÏÖ¸Ã×Ö¶ÎÊÇ×ÔÔöµÄ¡£

¶þ¡¢Laravel Ä£×Ó½â¾öÒªÁì

×Ô½ç˵Ö÷¼ü

ÔÚ Laravel Ä£×ÓÖУ¬¿ÉÒÔͨ¹ý $primaryKey ÊôÐÔÀ´×Ô½ç˵Ö÷¼ü¡£Àý£º

class User extends Model
{
    protected $primaryKey = 'user_id';
}

µÇ¼ºó¸´ÖÆ

ÕâÀォÖ÷¼üÉèÖÃΪ user_id¡£

½ûÓÃ×ÔÔöÖ÷¼ü

ÈôÊÇʹÓõÄÊÇ·Ç×ÔÔöÖ÷¼ü£¬ÐèÒª½« $incrementing ÊôÐÔÉèÖÃΪ false£¬ÒÔ½ûÓÃ×ÔÔöÖ÷¼ü¡£Àý£º

class Product extends Model
{
    public $incrementing = false;
}

µÇ¼ºó¸´ÖÆ

ÊÖ¶¯Ö¸¶¨Ö÷¼üÖµ

ÔÚһЩÌض¨µÄ³¡¾°Ï£¬¿ÉÄÜÐèÒªÊÖ¶¯Ö¸¶¨Ö÷¼üÖµ¡£Õâ¿ÉÒÔͨ¹ýÔÚÄ£×ÓÖÐÉèÖà $keyType ºÍ $fillable ÊôÐÔÀ´ÊµÏÖ¡£Àý£º

class Order extends Model
{
    protected $keyType = 'string';
    protected $fillable = ['order_id', 'product_name'];
}

µÇ¼ºó¸´ÖÆ

ÕâÀォÖ÷¼üÀàÐÍÉèÖÃΪ×Ö·û´®£¬²¢½ç˵ÁË¿ÉÌî³äµÄ×ֶΡ£

×ܽá

ͨ¹ýÒÔÉÏÒªÁ죬¿ÉÒÔ½â¾ö Laravel Ä£×ÓÖÐûÓÐÖ÷¼üµÄÎÊÌâ¡£ÔÚÏÖʵ¿ª·¢ÖУ¬¿ÉÒÔƾ֤ÏêϸÐèÇóÑ¡ÔñÏìÓ¦µÄÒªÁì¾ÙÐнâ¾ö¡£Í¬Ê±£¬ÐèҪעÖØ°ü¹ÜÖ÷¼üµÄΨһÐÔ£¬×èÖ¹¿ÉÄÜ·ºÆðµÄ³åÍ»ÎÊÌâ¡£

ÒÔÉϾÍÊÇlaravel ÌáÐÑûÓÐÖ÷¼üµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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