4中如何使用BIGINT作为自动增量主键

4中如何使用BIGINT作为自动增量主键

本文介绍了在Laravel 4中如何使用BIGINT作为自动增量主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模仿 wordpress的主键大小是BIGINT(20),但是laravel似乎没有本机功能..我看到了页面,并获得了如下代码:

I am trying to mimic wordpress' primary key size which is BIGINT(20) but it seems that laravel doesn't have a native function to do this.. I saw a page in the laravel forums and got a code like this:

$table->bigInteger('id')->primary();

但是当我尝试在artisan migrate期间将外键附加到该ID时,会抛出MYSQL错误:

but when i try to attach a foreign key to that id during artisan migrate, there is a MYSQL error that is thrown:

执行此操作的正确方法是什么?或者我在哪里弄错了这件事?

What is the proper way to do this or where do i get this thing wrong?

谢谢!

推荐答案

您很可能也忘记将role_id外键的类型也设置为BIGINT(20).这实际上不是Laravel问题,而是MySQL的问题.

You most likely forgot to also set the type of your role_id foreign key as BIGINT(20) as well. This isn't really a Laravel issue, but rather MySQL's.

顺便说一句,Laravel确实具有本机功能:

By the way, Laravel does have a native function to do this:

$this->bigIncrements('id');

这需要使其成为 unsigned 自动递增主键.

这篇关于在Laravel 4中如何使用BIGINT作为自动增量主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:04