Giter VIP home page Giter VIP logo

Comments (3)

mah3uz avatar mah3uz commented on May 23, 2024 2

I have got this same error.
I checked and found that initially the user_roles table created with 3 columns user_id, user_role & user_type with primary index in database/migrations/2017_09_14_000000_core_v1.php

And in database/migrations/2022_07_21_000000_core_v305.php its dropping primary index for user_id, user_role & user_type then adding primary index for user_id, user_role and last dropping the column user_type

So I assume that the purpose of this 2022_07_21_000000_core_v305.php migration is dropping the user_type column.
Instead of dropping primary index for all three column primary index I just drop only user_type index then drop the user_type column.

And it worked. I don't know any underlying consequences 😀

This is the code:

    public function up()
    {
        Schema::table('user_roles', function (Blueprint $table) {
            $table->dropPrimary(['user_type']);
//            $table->dropPrimary(['user_id', 'role_id', 'user_type']);
//            $table->primary(['user_id', 'role_id']);
        });

        Schema::table('user_roles', function (Blueprint $table) {
            $table->dropColumn('user_type');
        });
    }

from akaunting.

widada avatar widada commented on May 23, 2024 1

I got this error too.

In MySQL, you can't drop a primary key with "DROP INDEX IF EXISTS" as MySQL does not support the "IF EXISTS" clause with "DROP INDEX" or "DROP PRIMARY KEY". If a primary key does not exist, attempting to drop it results in an error, as you experienced.

I check on the database and I didn't see the primary key that we want to delete using this migration code

$table->dropPrimary(['user_id', 'role_id', 'user_type']);

So I've just tried to change the migration file database/migrations/2022_07_21_000000_core_v305.php like this

public function up()
{
    DB::statement('ALTER TABLE user_roles ADD PRIMARY KEY(`user_id`, `role_id`)');
}

Note: for column user_roles, make sure to include the DB_PREFIX.
e.g: if your DB_PREFIX=ak, So you need to change the table name to ak_user_roles

from akaunting.

cuneytsenturk avatar cuneytsenturk commented on May 23, 2024 1

This issue solved this commit

from akaunting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.