-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Sequelize create in the tables a column called "true" #12551
Comments
@jbarretodev I faced the same issue & went to dig into the code to find a reason for it. So, the reason for this can be found here. The model class in its
So for now, you can solve the problem by skipping the columns you do want (don't set them to @papb I have 2 suggestions to fix this issue and make the configuration of timestamps work as (intuitively) expected.
I can go ahead and open a PR for any of these solutions, just let me know which one will you prefer! |
@vishal-sood Man its work for me, thanks a lot! But its something strange that! someone must to fix that! |
@vishal-sood Fantastic! Thank you so much for taking the time to help!! Nice find! Indeed Thank you!! |
Updated Model.init method to accept only string and boolean values. Also, prevent a column named `true` from being created on the model whenever any timestamp fields (viz. 'createdAt', 'updatedAt', 'deletedAt') is set to `true` Closes sequelize#12551
Updated Model.init method to accept only string and boolean values. Also, prevent a column named `true` from being created on the model whenever any timestamp fields (viz. 'createdAt', 'updatedAt', 'deletedAt') is set to `true` Closes sequelize#12551
Issue Description
i dont know why! but sequelize is creating a column called "true".
i need help with this please!
here my codes:
`import { mainDBModelOption } from '..'
import {Model, DATE, INTEGER, STRING} from "sequelize";
import Sequelize from "sequelize";
import { ContactCreate, Contact_attributes } from "../../@types/contact_interface";
class Contact extends Model <Contact_attributes,ContactCreate> implements Contact_attributes{
public id!:number
public user!: number
public email!:string
public name!:string
public firstName!:string
public lastName!:string
public phoneNumber!:string
public companyName!:string
public website!:string
public address1!:string
public address2!:string
public postalCode!:string
public state!:string
public city!:string
public country!:string
public createdAt!:Date
public updatedAt!:Date
public deletedAt!:Date
}
Contact.init({
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user: {
type: STRING
},
email: {
type: STRING
},
name:{
type:STRING
},
firstName: {
type: STRING
},
lastName: {
type: STRING
},
phoneNumber: {
type: STRING
},
companyName: {
type: STRING
},
website: {
type: STRING
},
address1: {
type: STRING
},
address2: {
type: STRING
},
postalCode: {
type: STRING
},
state: {
type: STRING
},
city: {
type: STRING
},
country: {
type: STRING,
},
createdAt: {
type: DATE,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: DATE,
defaultValue: null
},
deletedAt: {
type: DATE,
defaultValue: null
}
},mainDBModelOption('contacts'));
export default Contact`
`
import { Sequelize, InitOptions } from 'sequelize'
import database from './database.config'
/**
*/
const mainDB = new Sequelize(
database.database,
database.username,
database.password,
{
host: database.host,
port: database.port,
dialect: database.dialect,
define: {
underscored: true,
timestamps: true,
createdAt: true,
updatedAt: true,
deletedAt: true,
paranoid: true,
}
}
)
export default mainDB
/**
/
export const modelOptionsFactory = (db: Sequelize) => (
modelName: string
): InitOptions => {
return {
sequelize: db,
modelName: modelName
}
}
/*
/
export const mainDBModelOption = modelOptionsFactory(mainDB)
/*
*/
export const connectFactory = (db: Sequelize): (() => Promise) => {
let connected = false
return async (): Promise => {
if (connected) return connected
await db.authenticate()
await db.sync()
connected = !connected
return connected
}
}
`
The text was updated successfully, but these errors were encountered: