2016-03-06 15 views
5

tên dự án của tôi là timecapturedjango 1.9 không tạo bảng cho mô hình người dùng tùy chỉnh

Dưới đây là phần có liên quan của timecapture/settings.py

INSTALLED_APPS = [ 
     # 'django.contrib.admin', 
     'django.contrib.auth', 
     'django.contrib.contenttypes', 
     'django.contrib.sessions', 
     'django.contrib.messages', 
     'django.contrib.staticfiles', 
     'timecapture', 
     'timesheet' 
     ] 

AUTH_USER_MODEL = 'timecapture.TimeUser' 

Và đây là timecapture/models.py

from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser 
) 
from django.utils.translation import ugettext_lazy as _ 
from django.db import models 
from django.utils import timezone 

class TimeUserManager(BaseUserManager): 
    use_in_migrations = True 
    def create_user(self, email, password=None): 
     """ 
      Creates and saves a User with the given email, date of 
      birth and password. 
     """ 
     if not email: 
      raise ValueError('Users must have an email address') 

     user = self.model(
       email=self.normalize_email(email), 
       ) 

     user.set_password(password) 
     user.save(using=self._db) 
     return user 

    def create_superuser(self, email, password): 
     """ 
      Creates and saves a superuser with the given email, date of 
      birth and password. 
     """ 
     user = self.create_user(email, 
       password=password, 
       ) 
     user.is_staff = True 
     user.save(using=self._db) 
     return user   

class TimeUser(AbstractBaseUser): 
    email = models.EmailField(
      verbose_name='email address', 
      max_length=255, 
      unique=True, 
      ) 
    is_active = models.BooleanField(
      _('active'), 
      default=True, 
      help_text=_(
       'Designates whether this user should be treated as active. ' 
       'Unselect this instead of deleting accounts.' 
       ), 
      ) 
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now) 
    first_name = models.CharField(_('first name'), max_length=30, blank=True) 
    last_name = models.CharField(_('last name'), max_length=30, blank=True) 
    is_staff = models.BooleanField(
      _('staff status'), 
      default=False, 
      help_text=_('Designates whether the user can log into this admin site.'), 
      ) 
    date_of_birth = models.DateField() 
    objects = TimeUserManager() 

    USERNAME_FIELD = 'email' 
    class Meta: 
     verbose_name = _('TimeUser') 
     verbose_name_plural = _('TimeUsers') 
     abstract = False 
     db_table = 'timeuser' 
     app_label = 'timecapture' 

    def get_full_name(self): 
     """ 
     Returns the first_name plus the last_name, with a space in between. 
     """ 
     full_name = '%s %s' % (self.first_name, self.last_name) 
     return full_name.strip() 

    def get_short_name(self): 
     "Returns the short name for the user." 
     return self.first_name 


    def __str__(self):    
     return self.email 

    def has_perm(self, perm, obj=None): 
     "Does the user have a specific permission?" 
     # Simplest possible answer: Yes, always 
     return True 

    def has_module_perms(self, app_label): 
     "Does the user have permissions to view the app `app_label`?" 
     # Simplest possible answer: Yes, always 
     return True 

    def email_user(self, subject, message, from_email=None, **kwargs): 
     """ 
     Sends an email to this User. 
     """ 
     send_mail(subject, message, from_email, [self.email], **kwargs) 

    @property 
    def is_staff(self): 
     "Is the user a member of staff?" 
     # Simplest possible answer: All admins are staff 
     return self.is_staff 

Các bảng trong db sau khi chạy di chuyển mới là:

| Tables_in_timecapture | 
+------------------------+ 
| auth_group    | 
| auth_group_permissions | 
| auth_permission  | 
| django_content_type | 
| django_migrations  | 
| django_session   | 

Tôi đã chơi xung quanh với các thiết lập siêu lớp trong mô hình bộ đếm thời gian của tôi, nhưng không có kết quả nào khác cho chúng. Khi tôi cố gắng tạo ra sử dụng hoặc siêu người dùng nó mang lại cho lỗi:

django.db.utils.ProgrammingError: (1146, "Table 'timecapture.timeuser' doesn't exist") 
+0

Bạn đã làm makemigrations và di cư? –

+0

@AswinMurugesh có, tôi thậm chí đã bỏ và tạo lại cơ sở dữ liệu của mình vài lần để kiểm tra kỹ lưỡng. – t0il3ts0ap

+0

@AswinMurugesh Xin chào, Thay vì chạy 'python manage.py makemigrations', tôi đã thử' python manage.py makemigrations timecapture' và nó đã tạo ra quá trình di chuyển. Điều đó đã xảy ra như thế nào? – t0il3ts0ap

Trả lời

5
python manage.py makemigrations 

Thay vì ở trên khi tôi đã cố gắng

python manage.py makemigrations timecapture 

Nó tạo ra sự di cư đối với mô hình người dùng tùy chỉnh

Các vấn đề liên quan