sqlmigrate und SQL untersuchen
Sehen Sie das rohe SQL, das eine Migration ausführt.
sqlmigrate und SQL untersuchen ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
See the Real SQL
Migrations are Python, but the database speaks SQL. The sqlmigrate command shows the exact SQL a migration will run.
How to Run It
Give sqlmigrate an app label and a migration number, and it prints the SQL without applying anything.
python manage.py sqlmigrate blog 0002It Does Not Apply
sqlmigrate is read-only. It prints the statements so you can review them, never touching your database.
Reading CREATE TABLE
An initial migration shows a CREATE TABLE with each column, type, and constraint laid out in plain SQL.
CREATE TABLE "blog_post" (
"id" integer PRIMARY KEY AUTOINCREMENT,
"title" varchar(200) NOT NULL
);Reading ALTER TABLE
Adding a field shows an ALTER TABLE ... ADD COLUMN, the precise change Django will make to the existing table.
ALTER TABLE "blog_post"
ADD COLUMN "published" bool NOT NULL DEFAULT 0;Why Inspect First
Previewing SQL catches surprises early, like an unexpected rebuild or a costly change on a huge table.
Dialect Matters
The SQL reflects your configured database. Postgres, SQLite, and MySQL each produce slightly different statements.
Find the Number
Need the migration number? Run showmigrations first to list them, then pass the one you want to sqlmigrate.
python manage.py showmigrations blogBackwards SQL
Add the --backwards flag to see the SQL Django would run to reverse a migration, useful before rolling back.
python manage.py sqlmigrate blog 0002 --backwardsA Learning Tool
sqlmigrate is a great way to learn how the ORM maps your models to tables, columns, indexes, and constraints.
Review Before Production
On important deploys, read the SQL for risky steps so a slow migration never locks your live tables unexpectedly.
Quick Check
What does python manage.py sqlmigrate do?
Recap
With sqlmigrate you preview the exact SQL behind any migration, forwards or backwards, so deploys hold no surprises. 🔍
Häufig gestellte Fragen
Ist die Lektion „sqlmigrate und SQL untersuchen“ kostenlos?
Ja — der vollständige Text von „sqlmigrate und SQL untersuchen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „sqlmigrate und SQL untersuchen“?
Sehen Sie das rohe SQL, das eine Migration ausführt. Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Django Academy zu starten?
Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „sqlmigrate und SQL untersuchen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?
Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- makemigrations vs. migrate
- Eine Migrationsdatei lesen
- Ein Model ändern und erneut migrieren
- sqlmigrate und SQL untersuchen