1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Id Unique Constraint Failed

Discussion in 'Mod Creation Help' started by ZackNAttack, Jan 10, 2020.

Tags:
  1. ZackNAttack

    ZackNAttack Chieftain

    Joined:
    Jan 2, 2020
    Messages:
    3
    Gender:
    Male
    For some reason, I'm recieving the following error twice in the database.log:
    Code:
    ERROR: UNIQUE constraint failed: Improvement_BonusYieldChanges.Id, Improvement_BonusYieldChanges.ImprovementType, Improvement_BonusYieldChanges.YieldType
    
    The only sql I have relating to the Improvement_BonusYieldChanges is the following:
    Code:
    INSERT INTO Improvement_BonusYieldChanges
            (ImprovementType,                YieldType,            BonusYieldChange,    PrereqTech,            PrereqCivic                    )
    VALUES    ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_CULTURE',    2,                    NULL,                'CIVIC_MERCANTILISM'        ),
            ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_GOLD',        2,                    'TECH_ECONOMICS',    NULL                        ),
            ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_GOLD',        2,                    NULL,                'CIVIC_PROFESSIONAL_SPORTS'    ),
            ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_CULTURE',    2,                    NULL,                'CIVIC_GLOBALIZATION'        ),
            ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_GOLD',        2,                    NULL,                'CIVIC_GLOBALIZATION'        );
    
    It doesn't have any Id column though.

    What am I doing wrong?
     
  2. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,205
    Location:
    Illinois, USA
    Code:
     ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_CULTURE',    2,                    NULL,                'CIVIC_MERCANTILISM'        ),
     ('IMPROVEMENT_ZACK_ONQ_UI',        'YIELD_CULTURE',    2,                    NULL,                'CIVIC_GLOBALIZATION'        ),
    Table <Improvement_BonusYieldChanges> does in fact have an "Id" column which defaults to a value of integer "0" when nothing is specified.
    Code:
    		<Row Id="6" ImprovementType="IMPROVEMENT_MINE" YieldType="YIELD_PRODUCTION" BonusYieldChange="1" PrereqTech="TECH_APPRENTICESHIP"/>
    		<Row Id="7" ImprovementType="IMPROVEMENT_MINE" YieldType="YIELD_PRODUCTION" BonusYieldChange="1" PrereqTech="TECH_INDUSTRIALIZATION"/>
    Since you want two rows in the table where the ImprovementType and the YieldType are the same, you need to provide an "Id" value for these two rows so the game can differentiate between the two rows.

    You will also have to do so for all the rows where the YieldType is 'YIELD_GOLD'.

    What is needed is that each new row added to the table have a unique combination of values for columns "Id", "ImprovementType", and "YieldType".
     
  3. ZackNAttack

    ZackNAttack Chieftain

    Joined:
    Jan 2, 2020
    Messages:
    3
    Gender:
    Male
    Thank you!
     

Share This Page