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

Error in foreign key #33

Open
jsDotx3 opened this issue Feb 11, 2017 · 3 comments
Open

Error in foreign key #33

jsDotx3 opened this issue Feb 11, 2017 · 3 comments

Comments

@jsDotx3
Copy link

jsDotx3 commented Feb 11, 2017

When you generate the foreign key, you need to add the unsigned () method to the corresponding field.

$table->integer('type_member') (When you perform the migration, it fails, because the unsigned method is missing)
$table->integer('type_member')->unsigned() (When you perfom the migration, it ok).

Documentation about Foreign Key: https://laravel.com/docs/5.4/migrations#foreign-key-constraints

Regards.

@VeeeneX
Copy link
Collaborator

VeeeneX commented Feb 20, 2017

@jsDotx3 It's already included can you give me an example of model?

@jsDotx3
Copy link
Author

jsDotx3 commented Feb 21, 2017

Yes,review.

https://mega.nz/#!kc9glJCD!cxcjYLLDErDES_eM_b2cm8inPGkDUbUZeIW3Js6dA78

Doesn't add method unsigned() in foreign key.

SO: Win10 x64.
Workbench: 6.3 CE

Regards.

@JeromeSpilmont
Copy link

Hello Guys,
Relation views aren't created during the migration.

for example.

It create this code (only Schema::create)

public function up()
{
Schema::create($this->set_schema_table, function (Blueprint $table) {
$table->engine = 'MyISAM';
$table->unsignedInteger('users_id');
$table->unsignedInteger('entities_id');

        $table->index(["entities_id"], 'fk_users_has_entities_entities1_idx');
        $table->index(["users_id"], 'fk_users_has_entities_users1_idx');
		$table->index(['users_id', 'entities_id'])->unique();

        $table->foreign('users_id', 'fk_users_has_entities_users1_idx')
            ->references('id')->on('users')
            ->onDelete('cascade')
            ->onUpdate('cascade');

        $table->foreign('entities_id', 'fk_users_has_entities_entities1_idx')
            ->references('id')->on('entities')
            ->onDelete('cascade')
            ->onUpdate('cascade');
    });
}

Instead of this code (with Schema::create & Schema::table)

public function up()
{
Schema::create($this->set_schema_table, function (Blueprint $table) {
$table->integer('users_id')->unsigned();
$table->integer('entities_id')->unsigned();
});

Schema::table('items_to_categories', function(Blueprint $table) {
    $table->foreign('users_id')->references('id')->on('users')
        ->onDelete('cascade')
        ->onUpdate('cascade');
    $table->foreign('entities_id')->references('id')->on('entities')
        ->onDelete('cascade')
        ->onUpdate('cascade');
    $table->index(['users_id', 'entities_id'])->unique();
});

}

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