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

Method QueryInterface.bulkDelete no longer working when the model parameter is missing. (PostgreSQL) #5615

Closed
pparlev opened this Issue Mar 21, 2016 · 12 comments

Comments

9 participants
@pparlev

pparlev commented Mar 21, 2016

When in a migration I'm trying to delete all the rows in one of my tables I get the following error
"TypeError: Cannot read property 'primaryKeys' of undefined".

My code looks like this

up: function(queryInterface, Sequelize) {
    return queryInterface.bulkDelete('Foo');
}

I expect that all rows matching a where condition get deleted.

This happens when using sequelize 3.19.3 with PostgreSQL.

IMO the bug is caused by the changes in this PR #5443.
More precisely, the exception occurs here as model is undefined.

@cgreening

This comment has been minimized.

cgreening commented Apr 25, 2016

In case anyone else comes here looking for a solution. You need to pass a dummy object for the last two arguments to get the bulkDelete to work as expected.

First argument should be the name of the table, second argument the where clause.

return queryInterface.bulkDelete('headings', { title: {$in: headingTitles} }, {}, {primaryKeys:[],primaryKeyAttributes:[]});

@Americas Americas referenced this issue Apr 26, 2016

Merged

only check model keys for delete with limit #5801

5 of 5 tasks complete
@markelog

This comment has been minimized.

markelog commented May 3, 2016

@janmeier could you release new version with this fix?

@janmeier

This comment has been minimized.

@prabhat4ever

This comment has been minimized.

prabhat4ever commented May 6, 2016

@cgreening you saved my life . . . thanks for that suggestion :-) 👍

@markelog

This comment has been minimized.

markelog commented May 6, 2016

@janmeier thank you!

@Hoverbear

This comment has been minimized.

Hoverbear commented Jun 3, 2016

This seems to produce a

Seed file failed with error: val.replace is not a function

Code:

    down: function (queryInterface, Sequelize) {
        return queryInterface.bulkDelete('Flags', {
            where: {
                keyword: [
                    "groupRegistration",
                    "memberRegistration",
                    "exhibitorRegistration",
                    "facilitatorRegistration",
                    "volunteerRegistration",
                    "workshopSignup"
                ]
            },
        }, {}, { primaryKeys:[], primaryKeyAttributes:[] });
    }
@diosney

This comment has been minimized.

Contributor

diosney commented Sep 19, 2016

It is happening me what @Hoverbear said (the Seed file failed with error: val.replace is not a function error).

There is any fix for the issue?

@diosney

This comment has been minimized.

Contributor

diosney commented Sep 19, 2016

Using MySQL adapter in my case.

@janmeier Any ideas?

@boxman0617

This comment has been minimized.

boxman0617 commented Sep 20, 2016

@diosney @Hoverbear Just remove the where. So instead of what you have do this:

    down: function (queryInterface, Sequelize) {
        return queryInterface.bulkDelete('Flags', {
            keyword: [
                "groupRegistration",
                "memberRegistration",
                "exhibitorRegistration",
                "facilitatorRegistration",
                "volunteerRegistration",
                "workshopSignup"
            ]
        });
    }

Also, you don't need to pass the last two arguments if you don't need them.

@diosney

This comment has been minimized.

Contributor

diosney commented Sep 20, 2016

@box Say whaaaaat!!! I can't believe it!!! What a catch man!

Worked like a charm! Finally someone who put some light into this! Thanks!

@boxman0617

This comment has been minimized.

boxman0617 commented Sep 20, 2016

@diosney no problem!

@firdanirp

This comment has been minimized.

firdanirp commented Jul 13, 2018

Guys i need to truncate the table use queryInterface. Is that possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment