Foreign Key onDelete not a function
See original GitHub issueTrying on add onDelete('CASCADE') to a parent_id foreign key. I’ve dropped the column with t.dropColumn('parent_id'), and now I’m trying to add the onDelete part. But t.foreign('parent_id').references('id').onDelete('CASCADE') doesn’t work because t.foreign(…).references(…).onDelete is not a function
How can I get this to work? Why can’t I chain onDelete to this foreign key creation?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Uncaught TypeError: this.props.onDelete is not a function reactjs
The problem comes from the line onDelete={this.remove}. This remove function is not defined. Is there anything your wnat to do in onDelete?
Read more >Django database integrity: ForeignKey on_delete options
The PROTECT argument of the ForeignKey on_delete option prevents the referenced object from being deleted if it already has an object ...
Read more >SQL Server: Foreign Keys with set null on delete
A foreign key with "set null on delete" means that if a record in the parent table is deleted, then the corresponding records...
Read more >SQLite Foreign Key Support
Foreign key ON DELETE and ON UPDATE clauses are used to configure actions that take place when deleting rows from the parent table...
Read more >Associations - Sequelize
For example, to use UUID as the foreign key data type instead of the default ... "fooId" INTEGER NOT NULL REFERENCES "foos" ("id")...
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 Free
Top 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

@elhigu please correct me if I’m wrong, for me this is not a bug due this example is not indicating the table to be related.
On this piece of code:
parent_idis the foreign key (assuming that it was defined before), but which is the table related?There’s 3 ways to reference a table in a foreign key definition:
referencesoninTable(which is an alias ofon)These 3 ways works perfectly with no issues.
Thirdly and finally, take a look at https://github.com/tgriesser/knex/blob/master/src/schema/tablebuilder.js#L202 there’s a condition to check if references contains a dot (
.), if don’t, there’s no return, that’s why you’re getting the error:onDelete is not a function@rbadillap Looks like you are right that those work fine, however better error message would be nice. I’m really surprised that
.references('tableName.id')and.references('id')returned different builder as a result (+ funnily it works in other order when cascade is given first and references last).