2

Hope you're well ! I have a question. How can I prevent the following error after a db reset (sync force true) please ?

SequelizeDatabaseError: type "enum_coverLists_supportingDocument" already exists

Here is what my model look like :

export const SUPPORTING_DOCUMENT = {
    MEDIATION_FEES: 'MEDIATION_FEES',
    LEGAL_COUNSEL_FEES: 'LEGAL_COUNSEL_FEES',
    FILING_COMPLAINT: 'FILING_COMPLAINT'
};

export const TYPE = {
    BUDGET: 'BUDGET',
    QUANTITY: 'QUANTITY',
    UNLIMITED: 'UNLIMITED'
};

const coverList = function (sequelize, Sequelize) {
    const coverList = sequelize.define('coverList',
        {
            id: {
                primaryKey: true,
                type: Sequelize.UUID,
                defaultValue: Sequelize.UUIDV4
            },
            title: {
                type: Sequelize.STRING,
                allowNull: false
            },
            description: {
                type: Sequelize.STRING,
                allowNull: true
            },
            supportingDocument: {
                type: Sequelize.ARRAY(Sequelize.ENUM({
                    values: [...Object.values(SUPPORTING_DOCUMENT)]
                })),
                validate: {
                    isIn: [...Object.values(SUPPORTING_DOCUMENT)],
                },
                allowNull: true
            }, 
            type: {
                type: Sequelize.ENUM,
                values: Object.values(TYPE),
                validate: {
                    isIn: [Object.values(TYPE)],
                },
                allowNull: false
            }
        });
    return coverList;
};
export default coverList;

Stack :

  • Node.js
  • PostgreSQL
  • Sequelize

Thanks in advance for your help.

5
  • Can you say more clearly the steps you take to get to this error? Commented Feb 22, 2021 at 19:16
  • Thanks for reaching out ! I just added "supportingDocument" field into my model & ran npm start. It worked at the first time, my table was created successfully, but when I ran npm start for the second time with db reset set to true I had this error. My table was not created on the second time though. I can't find the reason. I had the "type" field long before which contains enum & never had this error :/ Commented Feb 23, 2021 at 11:02
  • stackoverflow.com/q/60898055/8133717 Commented Feb 23, 2021 at 12:32
  • I have sync force true set but it changes nothing, Indeed, I have this error after a db reset for "supportingDocument" specific field. Type works well. I removed "supportingDocument" & have no problem reseting my db. Commented Feb 23, 2021 at 14:23
  • @nadia Which sequelize version are you using?(Please add it in question as well) |--| Also as per this issue github.com/sequelize/sequelize/issues/7812 , I think it should work properly. Commented Mar 20, 2021 at 19:51

1 Answer 1

2

So, Whenever you create an "enum" it will store in the database. if you are using pgAdmin it stores all enums in the "Types" folder and if you use dbeaver there it is stored in "dataTypes" folder. so from there, you can delete it... you can see here...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.