2012-12-29 4 views
0

저는 장고를 처음 사용 합니다만, 이것은 쉽지 않을 것 같습니다. 나는 장고 1.5 베타 2를 사용하고있다. 그러나 나는 이것처럼 단순한 것으로 충분히 안정되어야한다고 생각한다. 등록 앱에 수업이 있습니다.장고 외장 키를 사용할 수 없습니다.

그러나 하위 트랜잭션을 만들려고 할 때 실패합니다.

[email protected]:~/orthosie$ python manage.py shell 
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
(InteractiveConsole) 
>>> from register.models import Shift, Transaction 
>>> from django.utils import timezone 
>>> s = Shift(begin_date=timezone.now()) 
>>> s.transaction_set.create(begin_date=timezone.now()) 
Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 529, in create 

    return super(RelatedManager, self.db_manager(db)).create(**kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 149, in create 
    return self.get_query_set().create(**kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 394, in create 
    obj.save(force_insert=True, using=self.db) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 537, in save 
    force_update=force_update, update_fields=update_fields) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 632, in save_base 
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 215, in _insert 
    return insert_query(self.model, objs, fields, **kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1646, in insert_query 

return query.get_compiler(using=using).execute_sql(return_id) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 935, in execute_sql 
    cursor.execute(sql, params) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 41, in execute 
    return self.cursor.execute(sql, params) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 364, in execute 
    six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 362, in execute 
    return Database.Cursor.execute(self, query, params) 
IntegrityError: register_transaction.shift_id may not be NULL 
>>> 

내가 수동으로 sqliteman를 사용하여 SQLite는 데이터베이스에 파고하고 테이블 register_transaction가 shift_id 열이 사실 않는 것을 볼 수 있습니다.

-- Describe REGISTER_TRANSACTION 
CREATE TABLE "register_transaction" (
    "id" integer NOT NULL PRIMARY KEY, 
    "begin_date" datetime NOT NULL, 
    "finish_date" datetime, 
    "status" varchar(10) NOT NULL, 
    "shift_id" integer NOT NULL REFERENCES "register_shift" ("id") 
) 

제가 누락 된 작은 것이 있어야하는 것 같습니다.

답변

3

은 저장되지 않았으므로 ID가 없습니다.

전화를 걸기 전에 s.save()으로 전화하거나 Shift() 대신 Shift.objects.create을 사용하십시오.

+0

나는 이것이 어리 석고 쉽다는 것을 알았다. 정말 고맙습니다. –

관련 문제