0

我已经从 bitbucket 中提取了我的项目更新,并尝试了以下命令“python3 manage.py makemigrations”、“python3 manage.py migrate vehicle”、“python3 manage.py migrate”。但我收到以下错误。车辆应用程序是新的,它的一些模型使用来自之前迁移并在数据库中的其他应用程序的外键。我尝试了不同的方法,但找不到解决方案。我正在使用 django-1.7.4 我感谢任何建议。

return _bootstrap._gcd_import(name[level:], package, level)                                                                                            
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import                                                                                           
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load                                                                                        
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked                                                                               
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked                                                                                        
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module                                                                                  
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed                                                                             
  File "/apps/project/beta/apps/site/admin.py", line 7, in <module>                                                                                         
    from .forms import MenuSubItemAdminForm, MenuChildrenAdminForm                                                                                         
  File "/apps/project/beta/apps/site/forms.py", line 18, in <module>                                                                                        
    class AdvancedVehicleSearchForm(forms.Form):                                                                                                           
  File "/apps/project/beta/apps/site/forms.py", line 24, in AdvancedVehicleSearchForm                                                                       
    make_choices = [(make.id, '{} ({})'.format(make.name, make.stock_count)) for make in Make.objects.get_public().filter(stock_count__gt=0)]              
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/models/query.py", line 141, in __iter__                                       
    self._fetch_all()                                                                                                                                      
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/models/query.py", line 966, in _fetch_all                                     
    self._result_cache = list(self.iterator())                                                                                                             
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/models/query.py", line 265, in iterator                                       
    for row in compiler.results_iter():                                                                                                                    
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter                            
    for rows in self.execute_sql(MULTI):                                                                                                                   
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql                             
    cursor.execute(sql, params)                                                                                                                            
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/backends/utils.py", line 81, in execute                                       
    return super(CursorDebugWrapper, self).execute(sql, params)                                                                                            
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute                                       
    return self.cursor.execute(sql, params)                                                                                                                
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__                                               
    six.reraise(dj_exc_type, dj_exc_value, traceback)                                                                                                      
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/utils/six.py", line 658, in reraise                                              
    raise value.with_traceback(tb)                                                                                                                         
  File "/apps/project/.virtualenvs/beta/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute                                       
    return self.cursor.execute(sql, params)                                                                                                                
django.db.utils.ProgrammingError: relation "vehicle_make" does not exist                                                                                   
LINE 1: ..."."country_id", "vehicle_make"."stock_count" FROM "vehicle_m... 

车辆应用程序,制作模型:

from django.db import models
from django.utils.text import slugify
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from apps.location.models import Country
from project.abstract_classes import BaseModel, BaseManager
from .constants import FUEL_CHOICES, GEARBOX_GROUP_CHOICES, VEHICLE_TYPE_CHOICES

# Create your models here.
class Make(BaseModel):
    name = models.CharField(_('name'), max_length=50, unique=True, db_index=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE,
                                    null=True, related_name='makes')
    stock_count = models.PositiveIntegerField(_("Stock count"), default=0)

    objects = BaseManager()

    class Meta:
        ordering = ['country', 'name']

    def __str__(self):
        return self.name      

    def get_absolute_url(self):
        return reverse('vehicles-stock-by-make', kwargs={'make': slugify(self.name)})

设置.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'easy_thumbnails',
    'adminsortable',

    'apps.location',    
    'apps.vehicle',     
)  
4

1 回答 1

1

对于我所看到的,我尝试在运行迁移之前验证 AdvancedVehicleSearchForm,尝试以 django 可以首先进行迁移的方式将与车辆相关的表单传递给车辆应用程序。对于您在此处显示的文件,我无法为您提供更多帮助。我希望它能以某种方式帮助你

于 2017-02-16T10:15:31.003 回答