{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/6586","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/6586/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/6586/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/6586/events","html_url":"https://github.com/sequelize/sequelize/issues/6586","id":176202427,"number":6586,"title":"onDelete and sync() depends on order of associations","user":{"login":"seally1186","id":616824,"avatar_url":"https://avatars0.githubusercontent.com/u/616824?v=4","gravatar_id":"","url":"https://api.github.com/users/seally1186","html_url":"https://github.com/seally1186","followers_url":"https://api.github.com/users/seally1186/followers","following_url":"https://api.github.com/users/seally1186/following{/other_user}","gists_url":"https://api.github.com/users/seally1186/gists{/gist_id}","starred_url":"https://api.github.com/users/seally1186/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seally1186/subscriptions","organizations_url":"https://api.github.com/users/seally1186/orgs","repos_url":"https://api.github.com/users/seally1186/repos","events_url":"https://api.github.com/users/seally1186/events{/privacy}","received_events_url":"https://api.github.com/users/seally1186/received_events","type":"User","site_admin":false},"labels":[{"id":28979678,"url":"https://api.github.com/repos/sequelize/sequelize/labels/bug","name":"bug","color":"d7e102","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-09-10T20:50:56Z","updated_at":"2018-04-10T06:05:46Z","closed_at":null,"author_association":"NONE","body":"This seems like it may be related to some issues already reported, but I couldn't quite find it. Apologies if it's a duplicate.\n## What you are doing?\n\nHere are two minimal models, and two orders of adding associations between them.\n\n`````` js\nconst Sequelize = require(\"sequelize\");\nconst sequelize = new Sequelize(/*...*/);\n\nlet a = sequelize.define(\"a\", {\n  id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },\n}, {freezeTableName: true, timestamps: false});\nlet b = sequelize.define(\"b\", {\n  id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },\n  aId: { type: Sequelize.INTEGER, allowNull: false }\n}, {freezeTableName: true, timestamps: false});\n\nif (process.argv[2] == \"1\") {\n  a.hasMany(b);\n  b.belongsTo(a);\n} else {\n  b.belongsTo(a);\n  a.hasMany(b);\n}\nsequelize.sync({force: true, logging: console.log}).then(() => process.exit(0));```\n``````\n## What do you expect to happen?\n\nThe created foreign key probably shouldn't depend on whether we're in case 1 or 2.\n## What is actually happening?\n\n``` sql\n$ node test.js 1 | grep CREATE\nExecuting (default): CREATE TABLE IF NOT EXISTS \"a\" (\"id\"   SERIAL , PRIMARY KEY (\"id\"));\nExecuting (default): CREATE TABLE IF NOT EXISTS \"b\" (\"id\"   SERIAL , \"aId\" INTEGER NOT NULL \nREFERENCES \"a\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY (\"id\"));\n\n$ node test.js 2 | grep CREATE\nExecuting (default): CREATE TABLE IF NOT EXISTS \"a\" (\"id\"   SERIAL , PRIMARY KEY (\"id\"));\nExecuting (default): CREATE TABLE IF NOT EXISTS \"b\" (\"id\"   SERIAL , \"aId\" INTEGER NOT NULL \nREFERENCES \"a\" (\"id\") ON DELETE NO ACTION ON UPDATE CASCADE, PRIMARY KEY (\"id\"));\n```\n\nNote that the foreign key has `ON DELETE CASCADE` in case 1, but `ON DELETE NO ACTION` in case 2. I think the problem is that `hasMany` (and `hasOne`?) default to `onDelete: \"CASCADE\"`, while `belongsTo` (and `belongsToMany`?) default to `onDelete: \"NO ACTION\"`.\n\n**Dialect:** postgres\n**Database version:** 9.3.14\n**Sequelize version:** 3.24.2\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/379984341","html_url":"https://github.com/sequelize/sequelize/issues/6586#issuecomment-379984341","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/6586","id":379984341,"user":{"login":"sant123","id":7959437,"avatar_url":"https://avatars3.githubusercontent.com/u/7959437?v=4","gravatar_id":"","url":"https://api.github.com/users/sant123","html_url":"https://github.com/sant123","followers_url":"https://api.github.com/users/sant123/followers","following_url":"https://api.github.com/users/sant123/following{/other_user}","gists_url":"https://api.github.com/users/sant123/gists{/gist_id}","starred_url":"https://api.github.com/users/sant123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sant123/subscriptions","organizations_url":"https://api.github.com/users/sant123/orgs","repos_url":"https://api.github.com/users/sant123/repos","events_url":"https://api.github.com/users/sant123/events{/privacy}","received_events_url":"https://api.github.com/users/sant123/received_events","type":"User","site_admin":false},"created_at":"2018-04-10T06:05:46Z","updated_at":"2018-04-10T06:05:46Z","author_association":"NONE","body":"Shall this be added to the next milestone? https://github.com/sequelize/sequelize/milestone/18"}}
{"actor":{"display_login":"sant123"}}