You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider an example app with two models, Continent and Country, where a continent may have many countries, and a country must belong to one continent. The resources are set up as follows:
However, on posting this data the continent is successfully created, but then the process fails when creating the country, and the following traeback is returned:
Traceback (most recent call last):
File "lib/tastypie/resources.py", line 192, in wrapper
response = callback(request, *args, **kwargs)
File "lib/tastypie/resources.py", line 397, in dispatch_list
return self.dispatch('list', request, **kwargs)
File "lib/tastypie/resources.py", line 427, in dispatch
response = method(request, **kwargs)
File "lib/tastypie/resources.py", line 1165, in post_list
updated_bundle = self.obj_create(bundle, request=request, **self.remove_api_resource_names(kwargs))
File "lib/tastypie/resources.py", line 1784, in obj_create
self.save_m2m(m2m_bundle)
File "lib/tastypie/resources.py", line 1951, in save_m2m
related_bundle.obj.save()
File "lib/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "lib/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "lib/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "lib/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "lib/django/db/models/sql/compiler.py", line 791, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "lib/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "lib/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "lib/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
IntegrityError: null value in column "continent_id" violates not-null constraint
This issue can be worked around by specifying the backwards relation (à la this Stackoverflow post), but this then causes the related issue (or non-issue) #564.
The text was updated successfully, but these errors were encountered:
From #564. Similar to #307.
Consider an example app with two models,
Continent
andCountry
, where a continent may have many countries, and a country must belong to one continent. The resources are set up as follows:The use of
full=True
should mean that I am able to post JSON such as the following, in order to create one continent and one country beneath it:However, on posting this data the continent is successfully created, but then the process fails when creating the country, and the following traeback is returned:
This issue can be worked around by specifying the backwards relation (à la this Stackoverflow post), but this then causes the related issue (or non-issue) #564.
The text was updated successfully, but these errors were encountered: