-1

I have a question, when you create class and synchronize database brand me the following error.

(DjangoAvanzado)Ricardos-MacBook-Pro:SistemaDiscusiones ricardoeduardosaucedo$ python manage.py syncdb  --settings=SistemaDiscusiones.settings.local
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/ricardoeduardosaucedo/DjangoAvanzado/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/ricardoeduardosaucedo/DjangoAvanzado/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Users/ricardoeduardosaucedo/DjangoAvanzado/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/ricardoeduardosaucedo/DjangoAvanzado/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/ricardoeduardosaucedo/DjangoAvanzado/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/ricardoeduardosaucedo/Curso Django Avanzado/SistemaDiscusiones/apps/users/models.py", line 5
    class UserManager(BaseUserManager):
    ^
IndentationError: unexpected indent
1
  • Check your indentation. You are probably using tab instead of 4 spaces. Commented Sep 14, 2015 at 16:02

2 Answers 2

2

Tracebacks can look scary, but in this case, the message is quite clear if you start at the bottom and work up.

  File "/Users/ricardoeduardosaucedo/Curso Django Avanzado/SistemaDiscusiones/apps/users/models.py", line 5
    class UserManager(BaseUserManager):
    ^
IndentationError: unexpected indent

The error message is telling you you have an indentation error on line 5 of Avanzado/SistemaDiscusiones/apps/users/models.py.

Check you do not have any spaces at the beginning of that line, and that you are not using tabs. If you still can't fix the problem, edit your question and post the code from that file.

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

3 Comments

It still looks like there are spaces at the beginning of line 5. You need to remove those spaces, and fix the lines below if required.
Thank you very much, and achieved correct but now I get another error that is: LookupError: No installed app with label 'user'
That sounds like a different issue. You would be better to ask a new question, and show the full traceback, and your INSTALLED_APPS setting.
0
from django.db import models

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

    class UserManager(BaseUserManager):

        def _create_user(self, username, email, password, is_staff, is_superuser,
                **extra_fields):

            if not email:
                raise ValueError('El email debe de ser obligatorio')

            email = self.normalize_email(email)
            user = self.model(username=username, email=email, is_activate=True,
                    is_staff=is_staff, is_superuser=is_superuser, **extra_fields)
            user.set_password(password)
            user.save(using = self.db)
            return user

        def create_user(self, username, email, password=None,
                **extra_fields):    
            return self._create_user(username, email, password, False, False, **extra_fields)

        def create_superuser(self, username, email, password,
                **extra_fields):
            return self._create_user(username, email, password, True, True, **extra_fields)

    class User(AbstractBaseUser, PermissionsMixin):

        username = models.CharField(max_length=50, unique=True)
        email = models.EmailField(max_length=50, unique=True)
        first_name = models.CharField(max_length=100)
        last_name = models.CharField(max_length=100)
        avatar = models.URLField()


        objects = UserManager()

        is_activate = models.BooleanField(default=True)
        is_staff = models.BooleanField(default=False)

        USERNAME_FIELD = 'username'
        REQUIRE_FIELDS = ['email']

        def get_short_name(self):
            return self.username

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.