Replies: 2 comments 3 replies
-
Hello @jsardev! I checked your reproduction, thanks for providing it! When executing a migration, Payload starts a transaction and all the schema changes are done only in that transaction, until Payload will commit the transaction (which won't happen in your migration file, that's why you got await Promise.all(
['first', 'second'].map((name) =>
payload.create({
collection: 'tag',
data: {
name,
},
}),
),
) You need to pass the await Promise.all(
['first', 'second'].map((name) =>
payload.create({
req,
collection: 'tag',
data: {
name,
},
}),
),
) And I think this should work for you! I'm converting this to a discussion so we can keep the conversation. |
Beta Was this translation helpful? Give feedback.
-
@r1tsuu Hey! Thank you for a quick answer :) Unfortunately I already tried that and unfortunately it doesn't work as well: jsardev/payload-migration-issue@e4d9b40 I'm getting the exact same error that I mentioned in the initial post. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Bug
The migrations API exposes Payload Local API in the migration files. The problem is that when you do a
payload.create()
in a migration file, it won't work unless the schema didn't change overtime. It breaks the idempotency of migrations (you can't domigrate:fresh
)https://github.com/jsardev/payload-migration-issue/blob/518548b1d7988a27ee38307c9c30e2edbe85938b/src/migrations/20250512_140919.ts#L150-L162
Link to the code that reproduces this issue
https://github.com/jsardev/payload-migration-issue
Reproduction Steps
tags
collection withname
text fieldpayload migrate:create
payload.create()
tags
collectionpayload migrate:create
payload migrate:fresh
Which area(s) are affected? (Select all that apply)
db-sqlite
Environment Info
Beta Was this translation helpful? Give feedback.
All reactions