Drift detected on first migration
See original GitHub issueBug description
Hi,
I’m getting issues when trying to setup prisma on an existing database (I’ve already setup prisma on a new db without any issues)
At first I thought it was from my existing db but I’ve tried on a simple one:
CREATE TABLE `collections` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` date NOT NULL,
`slug` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `collections_slug_key` (`slug`),
KEY `collection_slug` (`slug`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO `collections` (`id`, `title`, `created_at`, `slug`)
VALUES
(1, 'test', '2022-02-01', 'test');
How to reproduce
- Install the db (above)
- Run npx prisma db pull
- Run npx prisma generate
- Run first migration npx prisma migrate dev
- Got this message saying that I have to reset my db
Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.
It should be understood as the set of changes to get from the expected schema to the actual schema.
If you are running this the first time on an existing database, please make sure to read this documentation page:
https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/troubleshooting-development
[+] Added tables
- collections
? We need to reset the MySQL database "test" at "127.0.0.1:3306"
Which is exactly the same db as the one I’ve pulled data from.
Expected behavior
Migrate without having to reset data
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model collections {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
created_at DateTime @db.Date
slug String @unique @db.VarChar(255)
@@index([slug], map: "collection_slug")
}
Environment & setup
- OS: Mac Os
- Database: Mysql 8.0.22
- Node.js version: v16.13.0
Prisma Version
prisma : 3.9.0
@prisma/client : 3.9.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio : 0.457.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Migrations - Drift - Simon Binder
Drift provides a migration API that can be used to gradually apply schema changes after bumping the schemaVersion getter inside the Database class....
Read more >Migration troubleshooting in development - Prisma
Database schema drift occurs when your database schema is out of sync with your migration history - the database schema has 'drifted away'...
Read more >Detecting Database Drift during Flyway Database Development
You can try migrating your pubs database to a version, altering the database manually (for example, just open SSMS and create a couple...
Read more >Detect and resolve drift in AWS Control Tower
Resolving drift · Many types of drift can be resolved through the Landing zone settings page. · If your OU has fewer than...
Read more >Tutorial: Using Flyway Check with SQL Server
-drift produces a report showing objects in the schema which are not the result of any of the currently applied migrations, i.e. changes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh yeah sorry. I forgot that
--create-only
won’t render the migration before it asks for reset. You can do the following instead.You should also add a lock file manually here since you will creating the migrations folder by hand in
prisma/migrations/migration_lock.toml
No,
migrate diff
was actually released today. Good timing 😃