Laravel schema builder primary key as foreign key

断了今生、忘了曾经 提交于 2019-12-06 11:03:45

based on Laravel Documentation Api on the below link, only string() method can have length attribute. Laravel Documentation Api

So to make those two column unsigned and not primary key or auto increment make the following change:

from this:

$table->integer('relid', 10);
$table->integer('currency', 10);

to this:

$table->integer('relid', false, true);
$table->integer('currency', false, true);

Because as per the documentation the integer() method syntax is:

integer(string $column, bool $autoIncrement = false, bool $unsigned = false)

And what you did is you assigned a value (10) to a boolean variable ($autoIncrement) which will always returns true on this case. For further proof of this, please refer back to the below link from php.net. php.net Boolean

I had the same issue before, and when I start referring back Laravel documentation 90% of confusion will be cleared. Hope this helps you.


Note: you can also use unsignedInteger() method, which i think it's more explicit and easier to remember:

unsignedInteger(string $column, bool $autoIncrement = false)

So the code will be like so:

$table->unsignedInteger('relid');
$table->unsignedInteger('currency');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!