{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/5691","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/5691/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/5691/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/5691/events","html_url":"https://github.com/sequelize/sequelize/issues/5691","id":145453056,"number":5691,"title":"place JSON in findOrCreate will throw error","user":{"login":"lcjnil","id":5821684,"avatar_url":"https://avatars.githubusercontent.com/u/5821684?v=3","gravatar_id":"","url":"https://api.github.com/users/lcjnil","html_url":"https://github.com/lcjnil","followers_url":"https://api.github.com/users/lcjnil/followers","following_url":"https://api.github.com/users/lcjnil/following{/other_user}","gists_url":"https://api.github.com/users/lcjnil/gists{/gist_id}","starred_url":"https://api.github.com/users/lcjnil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcjnil/subscriptions","organizations_url":"https://api.github.com/users/lcjnil/orgs","repos_url":"https://api.github.com/users/lcjnil/repos","events_url":"https://api.github.com/users/lcjnil/events{/privacy}","received_events_url":"https://api.github.com/users/lcjnil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-03T04:48:01Z","updated_at":"2016-04-03T16:49:12Z","closed_at":null,"body":"## What you are doing?\r\nBackground: sequelize(3.20.0), postgres(9.5.1)\r\n\r\nI am trying to create a new schema, and insert some data, and it throw an error, here is the code. \r\n\r\n```js\r\nconst Sequelize = require('sequelize');\r\nconst sequelize = require('./db');\r\nconst rateTypes = ['self', 'peer', 'oneToMany', 'manyToOne'];\r\nconst Promise = require('bluebird');\r\n\r\nconst RateGroup = sequelize.define('rate_group', {\r\n  name: {\r\n    type: Sequelize.STRING,\r\n    field: 'name'\r\n  },\r\n  fields: {\r\n    type: Sequelize.JSON,\r\n    field: 'fields'\r\n  },\r\n  type: {\r\n    type: Sequelize.ENUM(...rateTypes),\r\n    field: 'type'\r\n  }\r\n});\r\n\r\nPromise.coroutine(function *() {\r\n  yield RateGroup.sync();\r\n  yield RateGroup.findOrCreate({\r\n    where: {\r\n      name: 'test',\r\n      type: 'self',\r\n      fields: [{type: 'input', name: '123'}]\r\n    }\r\n  })\r\n})().then(() => console.log('Rate Group Table Sync Success!'));\r\n\r\n```\r\n\r\noutput is \r\n```\r\n❯ node server/model/rate_group.js                                                                                                                                                             [12:42:07]\r\nExecuting (default): SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'public' AND t.typname='enum_rate_groups_type' GROUP BY 1\r\nExecuting (default): CREATE TABLE IF NOT EXISTS \"rate_groups\" (\"id\"   SERIAL , \"name\" VARCHAR(255), \"fields\" JSON, \"type\" \"public\".\"enum_rate_groups_type\", \"createdAt\" TIMESTAMP WITH TIME ZONE NOT NULL, \"updatedAt\" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY (\"id\"));\r\nExecuting (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'rate_groups' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;\r\nExecuting (e6ac25f0-7e27-4771-a79e-81375b0f4960): START TRANSACTION;\r\nExecuting (e6ac25f0-7e27-4771-a79e-81375b0f4960): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\r\nExecuting (e6ac25f0-7e27-4771-a79e-81375b0f4960): COMMIT;\r\nUnhandled rejection TypeError: val.replace is not a function\r\n    at Object.SqlString.escape (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/sql-string.js:61:15)\r\n    at Object.QueryGenerator.escape (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:973:22)\r\n    at /Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2165:23\r\n    at Array.map (native)\r\n    at Object.QueryGenerator.whereItemQuery (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2164:49)\r\n    at /Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1865:25\r\n    at /Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/node_modules/lodash/lodash.js:4040:15\r\n    at baseForOwn (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/node_modules/lodash/lodash.js:2573:24)\r\n    at Function.forOwn (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/node_modules/lodash/lodash.js:11030:24)\r\n    at Object.QueryGenerator.whereItemsQuery (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1864:9)\r\n    at Object.QueryGenerator.getWhereConditions (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2289:19)\r\n    at Object.QueryGenerator.selectQuery (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1454:28)\r\n    at QueryInterface.select (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/query-interface.js:661:25)\r\n    at null.<anonymous> (/Users/nil/Documents/School_Project/new-rate/client/node_modules/sequelize/lib/model.js:1408:32)\r\n    at tryCatcher (/Users/nil/Documents/School_Project/new-rate/client/node_modules/bluebird/js/release/util.js:16:23)\r\n    at Promise._settlePromiseFromHandler (/Users/nil/Documents/School_Project/new-rate/client/node_modules/bluebird/js/release/promise.js:503:31)\r\n```\r\n\r\nhowever, if I replace `findOrCreate` with `create`, it would be working.\r\n\r\nFirst time to submit a issues, if i was doing wrong, please inform me the right way"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/205008881","html_url":"https://github.com/sequelize/sequelize/issues/5691#issuecomment-205008881","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/5691","id":205008881,"user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"created_at":"2016-04-03T16:49:12Z","updated_at":"2016-04-03T16:49:12Z","body":"The first problem that's reported, your code is missing the `.catch` section in the end.\r\n\r\nYou cannot use promises without `.catch`. Add, one, and then log what it is reporting as the problem. Then it will be possible to analyze."}}