اذهب إلى المحتوى
  • 0

كيف أغيّر اسم Model باستخدام Django/South؟

Simoh

السؤال

بعد الكثير من البحث، أود طرح سؤالي هنا، أريد تغيير اسم Model على Django باستخدام South ولدي:

class Foo(models.Model):
    name = models.CharField()

class FooTwo(models.Model):
    name = models.CharField()
    foo = models.ForeignKey(Foo)

وقد حاولت تغييره (Model) بالشكل التالي:

class Bar(models.Model):
    name = models.CharField()

class FooTwo(models.Model):
    name = models.CharField()
    foo = models.ForeignKey(Bar)

حيث حاولت تغيير الاسم من Foo إلى Bar، لكنه أهمل foo الموجودة داخل FOOTOW، كيف أتمكن من تغيير اسم Model باستخدام Django/Sourh؟

 

 

تم التعديل في بواسطة Simoh
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

بالنسبة لتغيير model/tabel فقط عليك بالأمر التالي:

./manage.py schemamigration yourapp rename_foo_to_bar --empty

وفي حال كنت تستعمل نسخة قديمة، استبدل startmigration عوضschemamigration.

ليكون التغيير اليدوي للكود بالشكل التالي:

class Migration(SchemaMigration):

    def forwards(self, orm):
        db.rename_table('yourapp_foo', 'yourapp_bar')


    def backwards(self, orm):
        db.rename_table('yourapp_bar','yourapp_foo')   

يمكنك إنجاز هذه العملية -تغيير الاسم- باستخدام db_table من Model الخاصة بالجدول، لكن في كل مرة تفعل ذلك سيبقى مشكل الاحتفاظ بالاسم القديم في بعد مواضع الموقع، لذا تستحب الطريقة الأولى لتفادي أي مشكل.

مما يدعو إلى ظهور هذه الرسالة :

The following content types are stale and need to be deleted:

    yourapp | foo

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...