Search code examples
python-3.7django-2.1makemigrations

__init__() missing 2 required positional arguments: 'from_fields' and 'to_fields' when making migration


I'm just starting to learn about python and django altogether.

Im having the error when I try run makemigrations command.

added_by = models.ForeignObject(User, default=1, verbose_name="ItemCategory",  on_delete=models.CASCADE)

I have researched other questions regarding this issue on google and I watched the recent video tutorials that have similar issues to this but their solution seems to work.

I'm using python 3.7 and django 2.15

Please help because its really frustrating since almost all codes I see are working but mine is not.

Thanks.

class ItemCategory(models.Model):
    name = models.CharField(max_length=100, blank=False, unique=True)
    description = models.TextField()
    added_by = models.ForeignObject(User, default=1, 
        verbose_name="ItemCategory",  on_delete=models.CASCADE)
        updated_by = models.ForeignObject(User, default=1, 
        on_delete=models.CASCADE)
    date_added = models.DateTimeField(auto_now=True)
    date_updated = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name_plural = "Item Categories";

    def __str__(self):
        return self.name + " " + self.description

Solution

  • I solved the problem by using models.ForeignKey instead.