InnoDB - errno: 1005, sqlState: 'HY000' sqlMessage: "Can't create table (tableName) (errno: -1)",

50 Views Asked by At

I was trying to make club, and students database

I am using sequelize, my engine is innoDB and I wrote like this

module.exports = (seq, DataTypes) => {
    const Club = seq.define("clubs", {
        id: {
            type: DataTypes.TINYINT,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        leader: {
            type: DataTypes.MEDIUMINT.UNSIGNED,
            allowNull: false
        },
        subleader: {
            type: DataTypes.MEDIUMINT.UNSIGNED,
            allowNull: false
        },
        type: {
            type: DataTypes.TINYINT,
            allowNull: false
        }},
        
        {timestamps: false,
        tableName: "clubs"}
    );

    Club.associate = (models) => {
        Club.belongsTo(models.users, {
            foreignKey: "leader",
            targetKey: "id",
            onDelete: "RESTRICT",
            onUpdate: "CASCADE"
        });

        Club.belongsTo(models.users, {
            foreignKey: "subleader",
            targetKey: "id",
            onDelete: "RESTRICT",
            onUpdate: "CASCADE"
        });

        Club.belongsTo(models.clubtype, {
            foreignKey: "type",
            targetKey: "id",
            onDelete: "SET DEFAULT",
            onUpdate: "CASCADE"
        })

        Club.belongsToMany(models.users, {
            through: models.user_club,
            foreignKey: "clubID"
        });
    };

    return Club;
};

However, this returned me an error code: 'ER_CANT_CREATE_TABLE', errno: 1005, sqlState: 'HY000', sqlMessage: "Can't create table 'dbjshsus.clubs' (errno: -1)",

I was stuck in this error for hours, so I tried another way: I opened my dbeaver, connected with my db,

and created a table names "clubs", and set my engine "innoDB"

However, this returned me an error "Can't create table 'dbjshsus.clubs' (errno: -1)"

I've searched about this error errno -1 but I couldn't find anything

I Also switched my engine to MyISAM, and then the table was created successfully...

I dont have any problems with foreign Keys, and it even worked couple hours ago. In same code dbjshsus.clubs was created successfully in innoDB, but not now

I changed my db names... and some of them works... But the name also gets into same problem... at some point, I can't use those names anymore...

I literally have no idea why is this error happening

Can Anyone give me the reason, and some solutions?

+ And Yes This is same problem with Can't create InnoDB table (error -1)

This didn't helped me that much..

0

There are 0 best solutions below