Why did I get error for python manage.py syncdb (I

2019-07-27 21:59发布

from django.db import models


class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.CharField(max_length=1000)
    created = models.DateField()
    modified = models.DateField()

Error for python manage.py syncdb:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
    self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/user1/djangoblog/../djangoblog/blog/models.py", line 7
    created = models.DateField()
    ^
IndentationError: unexpected indent

3条回答
男人必须洒脱
2楼-- · 2019-07-27 22:34

I couldn't help but notice the snippet you posted used tabs. Try the same code indented with spaces.

查看更多
你好瞎i
3楼-- · 2019-07-27 22:41

You probably have spaces or tabs where there needs to be tabs or spaces.

查看更多
【Aperson】
4楼-- · 2019-07-27 22:42

Did you mix tabs and spaces in the file? That is the most common cause of such an error.

查看更多
登录 后发表回答