I was trying to add a new column as a foriegn key in existing table in laravel 9. But, it continuously giving SQL error. I want to create a simple category_id
as a foreign_key
in brand table.
The below code doesn’t work,
$table->integer('category_id')->unsigned()->nullable()->after('password');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('SET NULL');
2
Answers
Your
category_id
must be of big integer typeor
create user column like this
$table->unsignedBigInteger('device_id')->index()->nullable();
and
if your table exist create new migration class and alter table to add new column in your table
try:
See more about DB Column Types.