2016-08-01 23 views
2

我有一个在Windows上正常工作的django项目。我正试图将其转移到Ubuntu。有一些问题,当我运行python manage.py runserver 8000Django/mySQL - AttributeError:'ForeignKey'对象没有属性'IntegerField'

File "/home/zhaojf1/Web-Interaction-APP/fileUpload_app/models.py", line 151, in Machine number_pins = models.IntegerField(blank=True, null=True)

AttributeError: 'ForeignKey' object has no attribute 'IntegerField'

而且此列到机台是不是外键的项目存在。在views.py

代码:

140 class Machine(models.Model): 
141  model = models.ForeignKey('Model', db_column='model', blank=True, null=True) 
142  sn = models.CharField(max_length=50, blank=True) 
143  mine_lon = models.CharField(max_length=50, blank=True) 
144  mine_lat = models.CharField(max_length=50, blank=True) 
145  location = models.CharField(max_length=50, blank=True) 
146  total_hours = models.IntegerField(blank=True, null=True) 
147  travel_hours = models.IntegerField(blank=True, null=True) 
148  machine_id = models.IntegerField(primary_key=True) 
149  models = models.ForeignKey('Model', db_column='models', blank=True, null=True) 
150  # photo_set_num = models.IntegerField(blank=True, null=True) 
151  number_pins = models.IntegerField(blank=True, null=True) 
152  class Meta: 
153   managed = False 
154   db_table = 'machine' 

我有一个MySQL数据库和我从MySQL使用

$ python manage.py inspectdb > models.py

回答

4

你指定字段models阴影models进口直接生成models.py来自Django。您可以重命名字段:

other_name_for_models = models.ForeignKey('Model', db_column='models', blank=True, null=True) 

或用不同的名称

from django.db import models as django_models 

class Machine(django_models.Model): 
    models = django_models.ForeignKey('Model', db_column='model', blank=True, null=True) 
导入模块