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
1
  • just type your model from scratch using spaces carefully Commented Jan 6, 2012 at 12:52

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

What do you mean by mixing tabs with spaces?
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.
2

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

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.