简体   繁体   中英

“python manage.py makemigrations” Traceback errors after creating models.py in Django

All of these errors only started happening when i did the models.py, to the best of my knowledge i didn't write any of my code wrong. Previous "makemigrations" worked.

It seems like a lot of the Traceback errors have nothing to do with the models.py though.

(hopefully these are easy to read, sorry)

The traceback error:

Traceback (most recent call last):

File "manage.py", line 21, in main()

File "manage.py", line 17, in main execute_from_command_line(sys.argv)

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django /core/management/ init .py", line 401, in execute_from_command_line utility.execute()

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/core/management/ init .py", line 377, in execute django.setup()

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/ init .py", line 24, in setup apps.populate(settings.INSTALLED_APPS)

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models()

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name)

File "/usr/lib/python3.6/importlib/ init .py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level)

File "", line 994, in _gcd_import

File "", line 971, in _find_and_load

File "", line 955, in _find_and_load_unlocked

File "", line 665, in _load_unlocked

File "", line 678, in exec_module

File "", line 219, in _call_with_frames_removed

File "/home/alatimer/Environments/djangoproject/blog/models.py", line 6, in class Post(models.Model):

File "/home/alatimer/Environments/djangoproject/blog/models.py", line 9, in Post date_posted = models.DateTimeField(defualt=timezone.now)

File "/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/db/models/fields/ init .py", line 1107, in init super(). init (verbose_name, name, **kwargs)

TypeError: init () got an unexpected keyword argument 'defualt'

models.py:

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User


class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(defualt=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

I hope this is for

date_posted = models.DateTimeField(defualt=timezone.now) .

Try Migrate the model with out this field.If migrate then try

date_posted = models.DateTimeField(default=timezone.now,blank=True, null=True)

try

class Post(models.Model):
    title = models.CharField(max_length=100, blank=True, null=True)
    content = models.TextField(blank=True, null=True)
    date_posted = models.DateTimeField(defualt=timezone.now, blank=True, null=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

Well, the error actually says it all (last line):

TypeError: init() got an unexpected keyword argument 'defualt'

So, in your models.py this line should be corrected:

date_posted = models.DateTimeField(defualt=timezone.now)

It is not defualt, it is default. You made a typo!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM