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

[Question] Schema Builder Foreign Keys #240

Closed
ghost opened this issue Feb 2, 2013 · 1 comment
Closed

[Question] Schema Builder Foreign Keys #240

ghost opened this issue Feb 2, 2013 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 2, 2013

I am trying to understand how to add foreign key constraints in the schema builder. Having spent some time reading over https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Schema/Blueprint.php and https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php, I am afraid I still can't understand how to add foreign keys.

The argument to the foreign key can be a string or array which is referenced internally as $columns. Is this the name of the column on the table with the foreign key, or the name of the key on the relational table?

Many thanks!

Schema::create('comments', function($table)
{
    $table->increments('id');
    $table->integer('post_id')->foreign('post_id');
    $table->text('content');
    $table->timestamps();
});
@taylorotwell
Copy link
Member

Please post question on the Laravel forums. http://forums.laravel.io

The issues are reserved for true "issues" or bugs.

joelharkes added a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
dbpolito pushed a commit to dbpolito/framework that referenced this issue Oct 1, 2019
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

1 participant