ERROR

on_delete=SET_NULL 설정시 ERROR 발생

728x90
반응형
from django.contrib.auth.models import User
from django.db import models

# Create your models here.
class Article(models.Model):
    writer = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='arrticle')
    title = models.CharField(max_length=200, null=True)
    image = models.ImageField(upload_to='article/', null=False)
    content = models.TextField(null=True)

    created_at = models.DateField(auto_created=True, null=True)

 

ERRORS:articleapp.Article.writer:(fields.E320) Field specifies on_delete=SET_NULL, but cannot be null.        HINT: Set null=True argument on the field, or change the on_delete rule.

 

해결: null=True 속성을 추가해주면 해결된다.

728x90
반응형