1
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
juliomalegria
  • 24,229
  • 14
  • 73
  • 89
cola
  • 12,198
  • 36
  • 105
  • 165

3 Answers3

5

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

David Robinson
  • 77,383
  • 16
  • 167
  • 187
  • What do you mean by mixing tabs with spaces? – cola Jan 06 '12 at 13:18
  • In Python, you have two options for indentation- tabs or spaces (usually 4 spaces). While either works on its own, when you combine them in the same class or function definition it can cause unexpected behavior. This is possible if you downloaded code from another source, which used a different convention than you do, and then added to it. Try deleting all four lines of indentation and replacing them with either a tab each or (preferred) four spaces each. – David Robinson Jan 06 '12 at 13:36
2

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

Nate
  • 12,499
  • 5
  • 45
  • 60
1

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

synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91