2015-01-09 77 views
0

我與edx developer棧工作,當我試圖插入一個條目StudentModule我得到這個錯誤EDX學生模塊完整性錯誤

Traceback (most recent call last): 
    File "<console>", line 2, in <module> 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/manager.py", line 137, in create 
    return self.get_query_set().create(**kwargs) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/query.py", line 377, in create 
    obj.save(force_insert=True, using=self.db) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save 
    self.save_base(using=using, force_insert=force_insert, force_update=force_update) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base 
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert 
    return insert_query(self.model, objs, fields, **kwargs) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query 
    return query.get_compiler(using=using).execute_sql(return_id) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 912, in execute_sql 
    cursor.execute(sql, params) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute 
    return self.cursor.execute(sql, params) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 114, in execute 
    return self.cursor.execute(query, args) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute 
    self.errorhandler(self, exc, value) 
    File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler 
    raise errorclass, errorvalue 
IntegrityError: (1062, "Duplicate entry '5-i4x://Organization/EDDC/course/2015- 
Organization/EDDC/2015' 
for key 'courseware_studentmodule_student_id_635d77aea1256de5_uniq'") 

回答

0

看起來你有StudentModule模型student外鍵有unique=True屬性。如果是這樣,那麼你試圖保存StudentModule重複student

請注意,您的表格只能包含student == None的一條記錄(以防萬一您的stident外鍵具有null=True)。