[SQL-DB] Changing Column Data type in FK
Open
Nobody has claimed this yet.
bug
- Dominant language
- No language data
- Stars
- 610
- Forks
- 62
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 3
Description
What happened?
We want to add a relationship after the fact, the column already exists and we migrated it from text to uuid. And after that we added a One > Many relationship to an existing table.
Regular up
✖ Database apply failed: DAB server responded with error: 400 Bad Request
Details: Migration failed due to a database constraint violation. Reason: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_PromotionCalendars_storeProfile_id". The conflict occurred in database "bts-alpha-v1-6e039184-7fa1-4176-bd61-dea52eef15ce", table "dbo.StoreProfiles", column 'id'.
RootActivityId: 20122eb8-c9c2-4a25-9f4b-3a9ddd4a8ac9 (34.2s)
💡 You can manually run 'rayfin up db apply' after the workload is ready
🚀 Apply DAB configuration to server
📄 Reading config from: C:\src\ghe\domain-customer-planning\data-apps\bts-alpha\rayfin\.temp\dab-config.json
📡 Applying configuration to Rayfin server...
⚠️ Using force mode - DAB will accept configuration that may result in data loss
❌ Failed to apply configuration to remote endpoint
DAB server responded with error: 400 Bad Request
Details: Migration failed due to a database constraint violation. Reason: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_PromotionCalendars_storeProfile_id". The conflict occurred in database "bts-alpha-v1-6e039184-7fa1-4176-bd61-dea52eef15ce", table "dbo.StoreProfiles", column 'id'.
RootActivityId: b59f3a30-a7c9-4f4e-b1bf-9a9cfc36d76a
💡 Troubleshooting tips for remote apply:
• Verify the Rayfin item workload is running and healthy
• Check if 'rayfin up' completed successfully
• Ensure your network can reach the remote endpoint
Steps to reproduce
Initial Table
import { entity, authenticated, uuid, text, date, decimal, set, one } from '@microsoft/rayfin-core';
import { ReportingChain } from '../customer/ReportingChain.js';
@entity()
@authenticated('*')
export class PromotionCalendar {
@uuid() id!: string;
@uuid() reportingChain_id!: string;
@one(() => ReportingChain) reportingChain?: ReportingChain;
@text({ max: 200 }) name!: string;
@set('all', 'segment', 'country', 'customer') scope!: 'all' | 'segment' | 'country' | 'customer';
@uuid({ optional: true }) customerSegment_id?: string;
@text({ max: 10, optional: true }) country?: string;
@text({ optional: true }) storeProfile_id?: string;
@set({ default: 'all' }, 'all', 'brand', 'businessLine', 'segment', 'style', 'generic') articleScopeLevel!:
'all' | 'brand' | 'businessLine' | 'segment' | 'style' | 'generic';
@text({ optional: true }) brand_id?: string;
@text({ optional: true }) businessLine_id?: string;
@text({ optional: true }) productSegment?: string;
@text({ optional: true }) style_id?: string;
@text({ optional: true }) generic_id?: string;
@set('End of Season', 'Clearance', 'Promotion', 'Markdown') promoType!: 'End of Season' | 'Clearance' | 'Promotion' | 'Markdown';
@date() validFrom!: Date;
@date() validTo!: Date;
@text({ max: 200, optional: true }) upliftPolicy?: string;
@decimal({ precision: 5, scale: 2, optional: true }) upliftPercentage?: number;
@decimal({ precision: 5, scale: 2, optional: true }) discountPercentage?: number;
@text({ max: 200 }) planningEffect!: string;
}
Conversion to UUID
- @text({ optional: true }) storeProfile_id?: string;
+ @uuid({ optional: true }) storeProfile_id?: string;
Added Relationship
+ import { StoreProfile } from '../customer/StoreProfile.js';
@entity()
@authenticated('*')
export class PromotionCalendar {
....
@uuid({ optional: true }) storeProfile_id?: string;
+ @one(() => StoreProfile) storeProfile?: StoreProfile;
....
}
Environment
No response
Logs or screenshots
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with rayfin up db apply using the shown PromotionCalendar changes, then inspect the generated .temp/dab-config.json and the migration response. Trace how the existing storeProfile_id column and the new @one relationship become a foreign-key migration; done means the schema applies without the reported constraint violation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100