Problem with foreign key with the Laravel Schema Builder

I was trying to set a foreign key to a field but I found myself getting this error.

SQLSTATE[HY000]: General error: 1005 Can't create table 'database.#sql-448_10c' (errno: 150) (SQL: alter table `table` add constraint articletypes_articletype_id_foreign foreign key (`articletype_id`) references `articletypes` (`id`))

After a little time searching for this I found a solution. The problem it’s actually a simple problem. By default the Schema Builder sets all “increments” fields to Unsigned so the field in cuestion should be unsigned.

$table->string('article_type', 120);

Stackoverflow Answer


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s