'How to assign a database model to a user

    from django.db import models
    from datetime import datetime
    from django.contrib.auth.models import User


    class News(models.Model):
        user = models.ForeignKey(User, on_delete=models.CASCADE)
        headline = models.CharField(max_length=100)
        content = models.CharField(max_length=1000000)
        time_created = models.DateTimeField(default=datetime.now, blank=True)

i kept on trying this method but i keep getting an error" django.db.utils.OperationalError: no such column: blog_news.user_id "

I am trying to make a logged-in user view only his/her contributions



Solution 1:[1]

Did you use "python manage.py migrate" command? (and of course, after that "python manage.py makemigrations" command)

Probably, you didn't run these commands and the database can't find such a column.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Onur TaƧ