2016-08-01 15 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データベースを持っていると私はあなたのフィールドはmodelsがインポートmodels影を命名

$ python manage.py inspectdb > models.py

答えて

4

を使用してMySQLから直接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) 
関連する問題