0Pricing
Flask Academy · درس

لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all

تعرّف إلى مخاطر تعديل المخططات الحية يدويًا.

لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Schemas Always Change

Real apps evolve, so your tables must change too. You will add columns, rename fields, and drop old ones as features grow. 🔄

create_all Only Builds Once

Remember the limit you met earlier: create_all only makes missing tables. It never touches a table that already exists.

db.create_all()

The Tempting Bad Fix

One tempting fix is drop then recreate. It works in a demo, but it deletes every row, which is unthinkable in production.

db.drop_all()
db.create_all()

Editing by Hand Is Risky

Running raw ALTER TABLE by hand on a live database is fragile. One typo or missed step can corrupt data with no easy undo.

What a Migration Is

A migration is a small script that moves your schema from one version to the next in safe, repeatable steps.

Versioned and Ordered

Each migration has a version id and points to the one before it. Together they form an ordered history of every schema change.

Forward and Backward

A migration defines two paths: upgrade applies the change, and downgrade reverses it if something goes wrong.

def upgrade():
    ...

def downgrade():
    ...

Flask-Migrate Wraps Alembic

Flask-Migrate connects your app to Alembic, the tool that detects schema changes and writes the migration scripts for you.

It Tracks the Current Version

Migrations record the current schema version inside a table called alembic_version, so the tool always knows where you are.

Safe Across Every Environment

The same migration scripts run on your laptop, in CI, and in production, so every environment ends up with an identical schema.

When to Switch

Use create_all only for the very first prototype. The moment your model starts changing, move to migrations for good.

Quick Check

Your table exists and you just added a column. Why not rely on create_all?

Recap

You saw why create_all cannot evolve a schema and how migrations bring safe, versioned, reversible changes. 🎉

الأسئلة الشائعة

هل درس «لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all» مجاني؟

نعم — نص درس «لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.

ماذا ستتعلم في «لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all»؟

تعرّف إلى مخاطر تعديل المخططات الحية يدويًا. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟

لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟

نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all
  2. تهيئة عملية ترحيل وإنشاؤها تلقائيًا
  3. تطبيق الترحيل والتراجع عنه باستخدام upgrade
  4. مراجعة البرامج النصية المُنشأة وتحريرها
← العودة إلى Flask Academy