महत्वपूर्ण में GenericForeignKey के साथ एक मॉडल का एक उदाहरण नहीं बना सकता: यह सवाल प्रासंगिक नहीं रह गया है।प्रवास
एक Django 1.7 प्रवास मैं निम्नलिखित कोड के साथ प्रोग्राम के टिप्पणी प्रविष्टियों बनाने की कोशिश में:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
def create_genericcomment_from_bookingcomment(apps, schema_editor):
BookingComment = apps.get_model('booking', 'BookingComment')
Comment = apps.get_model('django_comments', 'Comment')
for comment in BookingComment.objects.all():
new = Comment(content_object=comment.booking)
new.save()
dependencies = [
('comments', '0001_initial'),
('django_comments', '__first__'),
]
operations = [
migrations.RunPython(create_genericcomment_from_bookingcomment),
]
और यह एक त्रुटि पैदा करता है: TypeError: 'content_object' is an invalid keyword argument for this function
एक ही कोड हालांकि, (यानी Comment(content_object=comment.booking)
) खोल में निष्पादित होने पर काम करता है।
मैं new = Comment()
के साथ एक खाली मॉडल बनाने के लिए और उसके बाद सभी आवश्यक फ़ील्ड सेट मैन्युअल लेकिन फिर भी मैं content_type
और object_pk
क्षेत्रों के हिसाब से निर्धारित करते हैं, वे वास्तव में content_type
सहेजा नहीं गया था की कोशिश की और मैं django.db.utils.IntegrityError: null value in column "content_type_id" violates not-null constraint
किसी भी विचार प्राप्त करने के लिए कैसे एक माइग्रेशन में एक सामान्य विदेशी कुंजी के साथ एक मॉडल सही ढंग से बनाएँ? या कोई कामकाज?
आप मॉडल पेस्ट कर सकते हैं? कम से कम प्रासंगिक बिट? मैं एक सामान्य स्थिति बनाने की कोशिश कर रहा हूं जो एक एम 2 एम क्षेत्र का लक्ष्य है। मॉडल के पास कोई संबंध क्षेत्र नहीं है। – tutuca