Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivot not working correctly #45

Closed
betteryourweb opened this issue May 31, 2015 · 2 comments
Closed

Pivot not working correctly #45

betteryourweb opened this issue May 31, 2015 · 2 comments

Comments

@betteryourweb
Copy link

When generating pivot table, the generator is putting ->unsigned() before >index() and is causing the index not to be created at the right time (I'm guessing) and causes a failure on creating the foreign keys. If I reorder and put the ->index() method first in the change, it creates the index and foreign keys

@Houbsi
Copy link

Houbsi commented Jul 14, 2015

I had the same issue,

but the issue is that you enter the "Model" Name in singular:

make:migration:pivot User Company

But in the created migration it uses as tablename for the foreign key the "singular"name instead of the default "multiple"name.

This:

$table->foreign('company_id')->references('id')->on('company')->onDelete('cascade');

Should be:

$table->foreign('company_id')->references('id')->on('companys')->onDelete('cascade');

@tabacitu
Copy link
Contributor

tabacitu commented Mar 8, 2020

Hi there, I see the code is now $table->foreign('{{columnTwo}}_id')->references('id')->on('{{tableTwo}}')->onDelete('cascade'); so I assume this has been fixed sometime between 2015 and 2020 😃

Closing. Thanks!

@tabacitu tabacitu closed this as completed Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants