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

Big Integer migrations for User role permissions in Laravel 5.8 #941

Open
grimlock591 opened this issue Mar 15, 2019 · 1 comment
Open

Comments

@grimlock591
Copy link

If you run the script to publish the migrations and later run the migrations you get an error because Laravel 5.8 uses big integer instead of Integer for its user table migrations.

@bbtony
Copy link

bbtony commented Mar 17, 2019

Try to replace the function up() in the migration with this:
`public function up()
{
DB::beginTransaction();

    // Create table for storing roles
    Schema::create('roles', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name')->unique();
        $table->string('display_name')->nullable();
        $table->string('description')->nullable();
        $table->timestamps();
    });

    // Create table for associating roles to users (Many-to-Many)
    Schema::create('role_user', function (Blueprint $table) {
        $table->bigInteger('user_id')->unsigned();
        $table->bigInteger('role_id')->unsigned();

        $table->foreign('user_id')->references('id')->on('users')
            ->onUpdate('cascade')->onDelete('cascade');
        $table->foreign('role_id')->references('id')->on('roles')
            ->onUpdate('cascade')->onDelete('cascade');

        $table->primary(['user_id', 'role_id']);
    });

    // Create table for storing permissions
    Schema::create('permissions', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name')->unique();
        $table->string('display_name')->nullable();
        $table->string('description')->nullable();
        $table->timestamps();
    });

    // Create table for associating permissions to roles (Many-to-Many)
    Schema::create('permission_role', function (Blueprint $table) {
        $table->bigInteger('permission_id')->unsigned();
        $table->bigInteger('role_id')->unsigned();

        $table->foreign('permission_id')->references('id')->on('permissions')
            ->onUpdate('cascade')->onDelete('cascade');
        $table->foreign('role_id')->references('id')->on('roles')
            ->onUpdate('cascade')->onDelete('cascade');

        $table->primary(['permission_id', 'role_id']);
    });

    DB::commit();
}

`
It works for me.

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

2 participants