defaultTo() doesn't JSON.stringify json columns
See original GitHub issueI’m on PostgreSQL 9.3.4 and ran
knex.schema.table('user', function(t) {
t.json('preferences').defaultTo({}).notNullable();
}).then(function () {
console.log('modified columns');
});
and got the result
Column | Type | Modifiers
--------------------------------+-----------------------+------------------------------------------
preferences | text | not null default '[object Object]'::text
It seems that defaultTo()
should call JSON.stringify()
.
P.S. I would think that table column type would be json
, but I didn’t set up this server, so it’s possible that the json
extensions are not enabled.
Issue Analytics
- State:
- Created 9 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
defaultTo() doesn't JSON.stringify json columns #280 - GitHub
I'm on PostgreSQL 9.3.4 and ran knex.schema.table('user', function(t) { t.json('preferences').defaultTo({}).notNullable(); }).then(function ...
Read more >Data from the object doesn't convert when using JSON.stringify
I'm stuck in this weird issue that I'm having hard time in understanding what's doing on. When a button is clicked it calls...
Read more >39 JSON in Oracle Database
Insert JSON data into the JSON column, using any of the methods available for Oracle Database. The following statement uses a SQL INSERT...
Read more >JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
Read more >Schema Builder | Knex.js
Adds a json column, using the built-in json type in PostgreSQL, MySQL and SQLite, defaulting to a text column in older versions or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Doing
t.json('data').defaultTo('{}');
works and checking PG returns as a default of'{}'::json
so all good.Could you just do
.defaultTo('{}')
?