JED BOYLE
JED BOYLE

Reputation: 85

Model migrations using Django (cant migrate)

I'm trying to migrate some model classes to the built-in Django SQL database admin, but I'm getting a TypeError when I try to migrate. What am I doing wrong?

The error and my code

Upvotes: 0

Views: 59

Answers (2)

Swetank Poddar
Swetank Poddar

Reputation: 1291

Welcome to stackoverflow!

Whenever you declare a foreign key in Django models, you are required to define what Django should do if the referenced entity is deleted.

According to Django documentation:

A many-to-one relationship. Requires two positional arguments: the class to which the model is related and the on_delete option.

You can read more about it here Django Official Documentation

To solve your problem simply add a on_delete attribute to your foreign keys like:

topic = models.ForeignKey(Topic, on_delete=models.CASCADE)

Upvotes: 1

Tané
Tané

Reputation: 156

looks like it required "on_delete" arg, try with:

line 16: topic = models.ForeignKey(Topic, on_delete=models.CASCADE)

Upvotes: 0

Related Questions