1

I recently came onto a project in which we have two applications that are virtually identical. We are using Django 1.4 and Postgresql 8.4. Both models have the following:

  class Author(models.Model):
    person = models.ForeignKey(Person)
    book = models.ForeignKey(Book)
    order = models.PositiveIntegerField(blank=True,null=True)
    institute = models.ForeignKey(Institution,blank=True, null=True)
    rank = models.ForeignKey(Rank,blank=True, null=True)

  class Institution(models.Model):
    name = models.CharField(max_length=200)
    parent_institution = models.ForeignKey('self', blank=True, null=True)
    location = models.ForeignKey(Location, blank=False, null=False)
    type = models.ForeignKey(InstitutionType, blank=False, null=False)

  class Person(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    middle_name = models.CharField(max_length=50,blank=True,null=True)
    gender = models.CharField(max_length=1,choices=GENDER_TYPE,blank=True,null=True)

  class InstitutionType(models.Model):
    type = models.CharField(max_length=255)

Is there a way to easily merge the two, either through SQL or through Django? I'm not quite sure what the best approach would be. My only issue is that there is a lot of foreign key references. Is there a good way in which you could change the primary keys of one application's table to be higher than the other application (essentially reassign primary keys in the second table starting where the first table ends) and have them trickle down and then eventually merge the two tables? Any sort of feedback would be much appreciated.

4

2 に答える 2

0

Alexanderが提案しているのがリンクではない場合は、djangomulti-dbサポートを使用して次のことを行うことができます。

  • 両方のアプリを同じデータベースとモデルで実行し続ける
  • 両方のモデルをゆっくりと切り離して、一方だけが使用されるようにしながら、移行/同期スクリプトを使用します
  • テストを書く:)
于 2012-07-18T20:56:57.780 に答える
0

Probably the most difficult thing in merging are models. If you use Django you should use South too. If you don't - try it. Take first application as a base. Add fields from second application and create schemamigration. Then move your data with datamigration from second application. Merge your code from the second app.

于 2012-07-18T20:41:23.683 に答える