Migration Disorder
The posts migration runs before the users migration, and uses SQLite syntax. Fix both.
The Problem
Migrations must execute in a specific order. If Table B has a foreign key pointing to Table A, Table A must be created first.
DALT's migration runner executes files in alphabetical order based on their filenames.
You have two migration files:
001_create_posts_table.sql002_create_users_table.sql
The posts table has a user_id column that REFERENCES users(id). Because 001 runs before 002, the migration crashes with an error: relation "users" does not exist.
Furthermore, the person who wrote the posts migration used SQLite syntax (INTEGER PRIMARY KEY AUTOINCREMENT) instead of the Postgres equivalent (BIGSERIAL PRIMARY KEY). DALT's runner normally auto-converts this for you, but for this course we want you to write raw, native Postgres SQL.
What You Need to Fix
Load this challenge:
php artisan challenge:start db-migrations-disorderTwo files are copied to database/migrations/:
001_create_posts_table.sql002_create_users_table.sql
- Rename the files so that the users table is
001_and the posts table is002_. - Open the posts migration (now
002_create_posts_table.sql) and changeINTEGER PRIMARY KEY AUTOINCREMENTtoBIGSERIAL PRIMARY KEY.
Hints
- Use your editor or
mvto rename the files. The test specifically checks the contents of001_create_users_table.sqland002_create_posts_table.sql. BIGSERIALis the Postgres type for a self-incrementing 8-byte integer.
Verify
php artisan challenge:verify