Tastypie で新しいインスタンスを作成しようとしていますが、外部キーでこのエラーが発生し続けます。これが私のものです:
モデル:
class SuggestionVote(models.Model):
created_by_user = models.ForeignKey(User)
date_created = models.DateTimeField(auto_now_add = True)
suggestion = models.ForeignKey(Suggestion)
class Suggestion(models.Model):
title = models.TextField(blank=True,null=True)
created_by_user = models.ForeignKey(User)
date_created = models.DateTimeField(auto_now_add = True)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.title
モデル リソース (独自の認証方法を使用):
class UserResource(ModelResource):
class Meta:
list_allowed_methods = ['get']
queryset = User.objects.all()
resource_name = 'user'
authentication = MyBasicAuthentication()
authorization = DjangoAuthorization()
class SuggestionResource(ModelResource):
class Meta:
list_allowed_methods = ['get']
queryset = Suggestion.objects.all()
resource_name = 'suggestion'
authentication = MyBasicAuthentication()
authorization = DjangoAuthorization()
class SuggestionVoteResource(ModelResource):
class Meta:
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
queryset = SuggestionVote.objects.all()
resource_name = 'suggestionvote'
authentication = MyBasicAuthentication()
authorization = DjangoAuthorization()
jQueryを使用した私のAPI呼び出し:
var data = JSON.stringify({
"suggestion": "/api/suggestion/1/",
"created_by_user": "/api/user/1/"
});
$.ajax({
url: 'http://127.0.0.1:8000/api/suggestionvote/',
type: 'POST',
contentType: 'application/json',
data: data,
dataType: 'json',
processData: false
});
そして、私が得るエラー:
(1048、\"列 'created_by_user_id' は null にできません\")
ここで何か不足していますか?