2016-09-19 1 views
0

Wir sind ein Team von Entwicklern arbeiten an Django-Projekt. Wir haben Probleme mit Django-Migrationen. Wenn ein Entwickler Änderungen am Modell vornimmt und makemigrations> migrate sequence ausführt, generiert er einige sqls im Migrationsverzeichnis. Wenn nun ein anderer Entwickler den Code zieht und dieselbe Sequenz ausführt, setzt er den Code in einen schlechten Zustand. Wir haben unser Migrationsverzeichnis lokal gelöscht, um das Problem zu beheben und manchmal alle Daten zu löschen. Nicht sicher, was wir falsch machen. Bitte schlagen Sie die richtige Art der Verwendung von Django-Migrationen vor.Django Migrationen gibt Fehler, wenn separat in verschiedenen Maschinen ausgeführt

Hinweis - Alle von uns verwenden separate Instanzen von DB in lokalen Rechner.

+0

Sie sollte zeigen, welche Fehler Sie bekommen. –

+0

Welche Datenbank und Django-Version verwenden Sie? – Windsooon

+0

@DanielRoseman, Fehler ändern sich - Im Moment bekomme ich diesen - zurück selb.cursor.execute (sql) django.db.utils.ProgrammingError: Beziehung "django_content_type" existiert bereits Ich kann sehen, es gibt Vorschläge für das mit Fake-Initial, das scheint bei mir nicht zu funktionieren. Ich glaube, wir haben ein grundlegendes Problem in der Art und Weise, wie wir Migrationen verwenden - ich möchte wissen, ob wir Django-Migrationen korrekt verwenden oder nicht. – timedout

Antwort

0

makemigrations erstellen, Dateien

By running makemigrations, you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration.

Migrations are how Django stores changes to your models (and thus your database schema) - they’re just files on disk. You can read the migration for your new model if you like; it’s the file polls/migrations/0001_initial.py.

unter Versionskontrolle, nachdem Sie die Migrationen-Datei bereitstellen, zum Beispiel 0001_initial.py. Andere Entwickler ziehen Sie einfach die Datei dann laufen

python manage.py sqlmigrate your_app 0001 # to see what happen 

python manage.py migrate your_app 0001 

Mehr über die Versionskontrolle:

Version control

Because migrations are stored in version control, you’ll occasionally come across situations where you and another developer have both committed a migration to the same app at the same time, resulting in two migrations with the same number.

Don’t worry - the numbers are just there for developers’ reference, Django just cares that each migration has a different name. Migrations specify which other migrations they depend on - including earlier migrations in the same app - in the file, so it’s possible to detect when there’s two new migrations for the same app that aren’t ordered.

When this happens, Django will prompt you and give you some options. If it thinks it’s safe enough, it will offer to automatically linearize the two migrations for you. If not, you’ll have to go in and modify the migrations yourself - don’t worry, this isn’t difficult, and is explained more in Migration files below.

Verwandte Themen