Active Record represents a database row as an object that carries its data, persistence operations, and related domain behavior. A Rails `ActiveRecord::Base` model is a well-known implementation. Load a row, change an attribute, and call `save`; the framework issues SQL, so the pattern reduces repetitive mapping code without hiding SQL, transactions, or schema constraints. [Martin Fowler: Active Record](https://martinfowler.com/eaaCatalog/activeRecord.html) [Rails 8.1: Active Record Basics](https://guides.rubyonrails.org/active_record_basics.html)
A Django migration records a model change as an ordered Python file and applies its operations to the database schema. After editing a model, create a draft with `makemigrations`, review it, then apply it with `migrate`. Keep migration files in version control with the code; determine order from dependencies and inspect the generated SQL instead of relying on filename numbers alone.
Prisma Migrate records changes to `schema.prisma` as SQL migration files and applies that history to databases in different environments. During development, `migrate dev` creates and applies a migration. In production, use `migrate deploy` to apply reviewed, version-controlled migrations instead. Review generated SQL for data loss, renames, and the actual target before applying it.
Alembic records schema changes for a SQLAlchemy project as revision scripts and moves a database through them by following their links. The `--autogenerate` option compares SQLAlchemy model metadata with the current database and creates a candidate script; it does not guarantee a finished migration. Review and edit every candidate. A typical workflow is to change a model, generate and inspect a revision, run `upgrade head`, and check the result with `current`.
Liquibase records database changes in a file called a changelog, then applies only the changesets that have not yet been run on the target database. Keeping that file under version control with application code helps development, test, and production environments follow the same change sequence. The basic workflow is to record a change, inspect it with `validate` and `status`, review the SQL that would be generated, and then run `update`.
Flyway versions SQL and other migration files so database structure and data can be changed in the same order across environments. A new database can receive migrations from the beginning; an existing database usually needs a baseline recorded first, then only later changes are applied. A typical workflow is to create and review a file, inspect the target with `info`, check recorded history with `validate`, and then run `migrate`. Confirm the connection and baseline before pointing the tool at a live database.
Schema drift occurs when database object definitions differ from the state a team expects. For example, someone may add a column directly to production or remove an index during an incident without recording the change in the deployment history. Detect the difference, establish whether it was intentional, then incorporate it into version control or restore the expected state. Blindly overwriting a live schema can damage valid operational changes or data.
A database test fixture is the data and resources that put a test in a reproducible starting state. It may create a user or order needed by one test, then roll back or clean up so the next test is unaffected. Unlike seed data deployed as reference data, a fixture's lifetime belongs to the test run.
Seeding adds initial data so an application can start or a development and test database can be recreated. Reference values such as currencies or status codes have a different purpose and lifetime from sample users and posts. Version and deploy reference data consistently with schema changes; keep disposable fixtures in a separate, resettable development or test workflow. Explicitly restrict where each script may run so test accounts and reset logic cannot reach production. [Prisma ORM v7: Seeding](https://www.prisma.io/docs/orm/v7/prisma-migrate/workflows/seeding) [Flyway: Working with data](https://documentation.red-gate.com/fd/handling-data-138347109.html)
A migration checksum is a value some tools store to detect whether a migration file has changed since it was applied. Flyway records a CRC32 checksum for SQL migrations and compares it with the current file during `validate`. This detects file changes; it does not prove that the live schema matches the script or authenticate who changed it. When validation reports a mismatch, first establish what changed and compare the schema history and actual database state across environments. For Flyway, treat versioned migrations already applied downstream as immutable and make corrections in a new migration. [Flyway: Validate](https://documentation.red-gate.com/flyway/reference/commands/validate) [Flyway: Versioned migrations](https://documentation.red-gate.com/fd/versioned-migrations-273973333.html) [NIST: CRC](https://csrc.nist.gov/glossary/term/cyclic_redundancy_check)
An online schema change modifies a table while a service continues to read and write. First check whether the DBMS’s native online DDL supports the exact operation and concurrency level you need. For a large change that requires copying rows while tracking ongoing writes, a separate migration tool such as gh-ost may fit. “Online” does not mean impact-free: verify operation-specific locks, replication lag, extra resources, and the final cut-over, then rehearse on a representative replica. [MySQL 8.4: InnoDB Online DDL](https://dev.mysql.com/doc/refman/8.4/en/innodb-online-ddl.html) [GitHub gh-ost](https://github.com/github/gh-ost)
Expand-and-contract changes a database gradually, keeping old and new structures usable during a transition. First add the new structure, move application behavior and data, then remove the old structure last. It helps when application versions overlap or rollback must remain possible, but careless dual writes or backfills can create inconsistent data. AWS guidance recommends decoupling schema and code changes so old and new versions can coexist, and notes that reader/writer deployment order can differ between roll-forward and rollback. [AWS: Schema change practices](https://docs.aws.amazon.com/whitepapers/latest/blue-green-deployments/best-practices-for-managing-data-synchronization-and-schema-changes.html) [AWS DevOps Guidance](https://docs.aws.amazon.com/wellarchitected/latest/devops-guidance/dl.ads.5-ensure-backwards-compatibility-for-data-store-and-schema-changes.html)
A schema migration changes a database through versioned steps. Order those steps by the objects they depend on and by the application versions that must remain compatible—not just by filename. The right sequence for creating a database from scratch may differ from upgrading one already in use. Flyway applies versioned migrations in version order and tracks history and checksums; Alembic uses a revision graph rather than numeric filename order. [Flyway: Versioned migrations](https://documentation.red-gate.com/fd/versioned-migrations-273973333.html) [Alembic: Tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html)
Use an entity–attribute–value (EAV) model when each record has only a few of many possible, frequently changing attributes. EAV stores one entity’s one attribute value per row, so new optional properties do not require new columns. The trade-off is more work to define types, validate values, and query several attributes together; EAV is a targeted modeling choice, not a default replacement for ordinary tables. [JMIR](https://www.jmir.org/2003/4/e27)
title: "How to Design a Junction Table for Many-to-Many Relationships"
summary: "A junction table stores each association between two entities as a row. This guide shows how to prevent duplicate links, store relationship-owned fields, account for repeated offerings, and choose foreign-key delete behavior in PostgreSQL 18."
---
# How to Design a Junction Table for Many-to-Many Relationships
title: "How to Evaluate a BCNF Decomposition: Check Joins and Dependencies"
summary: "BCNF requires every determinant of a nontrivial functional dependency to be a superkey. A BCNF split can be lossless without preserving every dependency locally, so this guide checks both properties and helps choose an enforcement strategy."
---
# How to Evaluate a BCNF Decomposition: Check Joins and Dependencies
title: "How to Check Third Normal Form (3NF): Find Transitive Dependencies"
summary: "Third Normal Form (3NF) requires a relation to be in 2NF and, for every functional dependency X → A, either X to be a superkey or A to be a prime attribute. This guide tests that rule with a supplier and company example, shows a decomposition, and explains the narrower BCNF rule."
---
# How to Check Third Normal Form (3NF): Find Transitive Dependencies
A functional dependency `X → Y` means that, under a business rule, equal X values must imply equal Y values. Y depends fully on a composite X only if removing any attribute from X makes the dependency stop holding. If the dependency remains after removing part of X, it is partial.
First normal form (1NF) is a relational design rule: each row has the same fields, each cell contains one value from its column’s domain, and there are no repeating groups. In practice, values that need independent search, update, or constraints should not be stored as a delimited list or repeated `phone1`, `phone2` columns; model each value as a row. “Atomic” does not mean impossible to split in the abstract. It depends on whether the model needs to treat parts independently.
A column default is a value or expression the database supplies when an INSERT omits a column or explicitly requests DEFAULT. It does not validate data or repair existing rows. Omitting a column, writing NULL, and writing DEFAULT are different inputs.