Repository navigation
Closed
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Description
Issue Description
defaultValue for JSON DataType doesn't work.
What are you doing?
I am creating a model with a column called database and a defaultValue of a stringified JSON object.
Here is the link to the SSCCE for this issue: LINK-HERE
const server = sequelize.define("server", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
database: {
type: DataTypes.JSONB,
defaultValue: JSON.stringify({
enabled: false,
host: "localhost",
user: "root",
password: "",
name: "dbname",
}),
allowNull: false,
},
});
server.sync({ alter: true });What do you expect to happen?
The query for syncing the database column must be this:
ALTER TABLE `servers` CHANGE `database` `database` JSON NOT NULL DEFAULT '{\"enabled\":false,\"host\":\"localhost\",\"user\":\"root\",\"password\":\"\",\"name\":\"cod4x\"}';
What is actually happening?
But the query for syncing the database column is this:
ALTER TABLE `servers` CHANGE `database` `database` JSON NOT NULL;
Additional context
This works well with JSONB datatype but I'm using MySQL and I need JSON.
EDIT: I think this PR is causing the problem.
Environment
- Sequelize version: 6.5.0
- Node.js version: 14.15.4
- Operating System: WINDOWS 10 x64
- If TypeScript related: TypeScript version: 4.1.5
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Metadata
Metadata
Assignees
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Activity
github-actions commentedon Oct 27, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
nishantc7 commentedon Feb 22, 2022
Any Updates?
ephys commentedon Feb 22, 2022
https://dev.mysql.com/doc/refman/8.0/en/json.html
Looks like we can enable default JSON values for mysql 8
[-]`defaultValue` for JSON DataType doesn't work.[/-][+]`defaultValue` for JSON DataType doesn't work in MySQL in MySQL 8.[/+]