python - "unknown column X.id" error in django using existing DB -


i trying create model existsing db. using output of manage.py inspectdb, models.py file looks this:

from django.db import models  ...some more stuff here...  class scripts(models.model):     run_site = models.foreignkey(sites, db_column='run_site')     script_name = models.charfield(max_length=120)     module_name = models.charfield(unique=true, max_length=120)     type = models.charfield(max_length=24)     cat_name = models.charfield(max_length=90)     owner = models.foreignkey(qapeople, db_column='owner')     only_server = models.charfield(max_length=120, blank=true)     guest = models.integerfield()     registered = models.integerfield()     super = models.integerfield()     admin = models.integerfield()     run_timing = models.charfield(max_length=27)     manual_owner = models.foreignkey(qapeople, db_column='manual_owner')     script_id = models.integerfield(unique=true,)     version = models.integerfield()     comment = models.foreignkey('scriptcomments', null=true, blank=true)     class meta:         db_table = u'scripts' 

when try scripts.objects.all() get

traceback (most recent call last):   file "<console>", line 1, in <module>   file "c:\python26\lib\site-packages\django\db\models\query.py", line 68, in __repr__     data = list(self[:repr_output_size + 1])   file "c:\python26\lib\site-packages\django\db\models\query.py", line 83, in __len__     self._result_cache.extend(list(self._iter))   file "c:\python26\lib\site-packages\django\db\models\query.py", line 269, in iterator     row in compiler.results_iter():   file "c:\python26\lib\site-packages\django\db\models\sql\compiler.py", line 672, in results_iter     rows in self.execute_sql(multi):   file "c:\python26\lib\site-packages\django\db\models\sql\compiler.py", line 727, in execute_sql     cursor.execute(sql, params)   file "c:\python26\lib\site-packages\django\db\backends\util.py", line 15, in execute     return self.cursor.execute(sql, params)   file "c:\python26\lib\site-packages\django\db\backends\mysql\base.py", line 86, in execute     return self.cursor.execute(query, args)   file "c:\python26\lib\site-packages\mysqldb\cursors.py", line 173, in execute     self.errorhandler(self, exc, value)   file "c:\python26\lib\site-packages\mysqldb\connections.py", line 36, in defaulterrorhandler     raise errorclass, errorvalue operationalerror: (1054, "unknown column 'scripts.id' in 'field list'") 

why django think there should scripts.id column? how fix without dropping tables etc?

there default implicit id field auto incrementing primary key on every model. see primary_key in django docs how change field other name, there needs 1 primary key (also in table).

also may not want call 1 of fields super, since shadowing python's built-in super in class body. might give hard time finding bug day.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -