DataTypes.JSON dosn't work with seeding and arrays
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, mariadb
Direzione di ricerca
Start with the seed file's queryInterface.bulkInsert call and reproduce it using npx sequelize db:seed:all against MariaDB 10.5. Compare this path with the working model save example, then verify that a seeded JSON array is stored as an array and add or run a regression check for that behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What you are doing?
I used npx sequelize db:seed:all to seed a database entry.
If I try to create it in the project itself everything is working fine (see test file)
Test File
const { test } = require('./models')
let test1 = test.build({
arr: ['test1'],
createdAt: new Date(),
updatedAt: new Date()
})
test1.save()
Model File
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class test extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
test.init({
arr: DataTypes.JSON,
}, {
sequelize,
modelName: 'test',
});
return test;
};
Seed File
module.exports = {
async up (queryInterface, Sequelize) {
return queryInterface.bulkInsert('test',[
{
arr: ['test1'],
createdAt: new Date(),
updatedAt: new Date()
}
])
},
async down (queryInterface, Sequelize) {
return queryInterface.bulkDelete('test', null, {});
}
};
What do you expect to happen?
Insert a new row into the database with the array
What is actually happening?
The array isnt beeing parsed to ['test1'], it's getting parsed to 'test1'
ERROR: (conn=81, no: 4025, SQLState: 23000) CONSTRAINT `test.arr` failed for `database_dev`.`test`
INSERT INTO `tests` (`test`,`createdAt`,`updatedAt`) VALUES ('test','2022-09-14 09:17:45.936','2022-09-14 09:17:45.936');
Dialect: mariadb
Database version: 10.5.15
Sequelize CLI version: 6.4.1
Sequelize version: 6.21.6
- Lingua principale
- JavaScript
- Stelle
- 2.6k
- Fork
- 524
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sequelize/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Tutte le issue di sequelize/cli
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Automattic/studio#4908 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sugarlabs/musicblocks#8847 ·