violated - parent key not found error





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have the following error appearing:



INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm')
*
ERROR at line 1:
ORA-02291: integrity constraint (SHAHA1.IAM_IS_GROUP_FK) violated - parent key
not found


The constraint in the GroupMembers table is:



CONSTRAINT  iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name)


The Members Table looks like this:



CREATE TABLE Members (
group_name VARCHAR2(40),
CONSTRAINT g_id_pk PRIMARY KEY(group_name),
CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


All of the tables are created fine until it comes to creating the GroupMembers table. Anyone have any ideas? I've been scratching for quite a while.










share|improve this question

























  • I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

    – user3572072
    Apr 25 '14 at 8:11


















1















I have the following error appearing:



INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm')
*
ERROR at line 1:
ORA-02291: integrity constraint (SHAHA1.IAM_IS_GROUP_FK) violated - parent key
not found


The constraint in the GroupMembers table is:



CONSTRAINT  iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name)


The Members Table looks like this:



CREATE TABLE Members (
group_name VARCHAR2(40),
CONSTRAINT g_id_pk PRIMARY KEY(group_name),
CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


All of the tables are created fine until it comes to creating the GroupMembers table. Anyone have any ideas? I've been scratching for quite a while.










share|improve this question

























  • I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

    – user3572072
    Apr 25 '14 at 8:11














1












1








1


0






I have the following error appearing:



INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm')
*
ERROR at line 1:
ORA-02291: integrity constraint (SHAHA1.IAM_IS_GROUP_FK) violated - parent key
not found


The constraint in the GroupMembers table is:



CONSTRAINT  iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name)


The Members Table looks like this:



CREATE TABLE Members (
group_name VARCHAR2(40),
CONSTRAINT g_id_pk PRIMARY KEY(group_name),
CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


All of the tables are created fine until it comes to creating the GroupMembers table. Anyone have any ideas? I've been scratching for quite a while.










share|improve this question
















I have the following error appearing:



INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm')
*
ERROR at line 1:
ORA-02291: integrity constraint (SHAHA1.IAM_IS_GROUP_FK) violated - parent key
not found


The constraint in the GroupMembers table is:



CONSTRAINT  iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name)


The Members Table looks like this:



CREATE TABLE Members (
group_name VARCHAR2(40),
CONSTRAINT g_id_pk PRIMARY KEY(group_name),
CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


All of the tables are created fine until it comes to creating the GroupMembers table. Anyone have any ideas? I've been scratching for quite a while.







sql database oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 28 '13 at 11:06









Kiquenet

7,18627110200




7,18627110200










asked Nov 22 '12 at 18:23









AkshaiShahAkshaiShah

1,88072737




1,88072737













  • I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

    – user3572072
    Apr 25 '14 at 8:11



















  • I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

    – user3572072
    Apr 25 '14 at 8:11

















I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

– user3572072
Apr 25 '14 at 8:11





I'm scratching for the error,too. I've disabled the foreign constraint and did some insert and delete actions. After I updated, I could not enable this foreign constraint. It said ORA-02298: cannot validate (PRODUSR.SYS_C0037867) - parent keys not found. But I checked many times and still cannot find out any records not in parent table.

– user3572072
Apr 25 '14 at 8:11












3 Answers
3






active

oldest

votes


















2














The problem is that



CONSTRAINT iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name);
references the table Members on the group_name field.



This means that the field is_group on the table GroupMembers must have an identical value on the table Members and group_name field.



In my opinion this is bad practice.
First of all you should have a primary key field on the table GroupMembers. You should not store the names of the group members in the table GroupMembers, but their corresponding id from the table Members.



Also the table Members, should look something like this:



    CREATE TABLE Members (
member_id NUMBER PRIMARY KEY
member_name VARCHAR2(40),
CONSTRAINT g_id_pk PRIMARY KEY(member_id),
CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


Then on the table GroupMembers, I suppose you want to associate some members to their set of groups and back, so you should do something like this:



    CREATE TABLE GroupMembers (
member_id NUMBER,
group_id NUMBER
)
CONSTRAINT iam_is_member_fk FOREIGN KEY(member_id) REFERENCES Members(member_id);
CONSTRAINT iam_is_member_fk FOREIGN KEY(group_id) REFERENCES Groups(group_id);


Supposing that you have a table Groups containing all the group details, with the primary key stored as number , and name group_id.



Always remeber that each table must have a primary key. It is good practice for this key to be a number.



So by having member_id in Members, group_id in Groups, you can create a many to many relationship in GroupMembers. Also, put a unique index on this table so you don't have duplicates ( the same member associated to the same id several times ).



Look at this example linking users to roles. It is the same case:
enter image description here






share|improve this answer

































    0














    error is
    you have to use same column name which is defined in reference table



    i.e



    CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(group_name)



    That group_name should be define as primary key in Artist Table.






    share|improve this answer


























    • No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

      – b.enoit.be
      Feb 2 '15 at 13:05



















    0














    Order in which you are insert is the reason for the error.



    Members(group_name) does not contain Goldfrat. If this is not true then it's not there in the table Artists.






    share|improve this answer


























    • I'm inserting that line after i insert everything else

      – AkshaiShah
      Nov 22 '12 at 18:29











    • Ah yes of course, i missed that completely

      – AkshaiShah
      Nov 22 '12 at 18:34












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13518246%2fviolated-parent-key-not-found-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The problem is that



    CONSTRAINT iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name);
    references the table Members on the group_name field.



    This means that the field is_group on the table GroupMembers must have an identical value on the table Members and group_name field.



    In my opinion this is bad practice.
    First of all you should have a primary key field on the table GroupMembers. You should not store the names of the group members in the table GroupMembers, but their corresponding id from the table Members.



    Also the table Members, should look something like this:



        CREATE TABLE Members (
    member_id NUMBER PRIMARY KEY
    member_name VARCHAR2(40),
    CONSTRAINT g_id_pk PRIMARY KEY(member_id),
    CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


    Then on the table GroupMembers, I suppose you want to associate some members to their set of groups and back, so you should do something like this:



        CREATE TABLE GroupMembers (
    member_id NUMBER,
    group_id NUMBER
    )
    CONSTRAINT iam_is_member_fk FOREIGN KEY(member_id) REFERENCES Members(member_id);
    CONSTRAINT iam_is_member_fk FOREIGN KEY(group_id) REFERENCES Groups(group_id);


    Supposing that you have a table Groups containing all the group details, with the primary key stored as number , and name group_id.



    Always remeber that each table must have a primary key. It is good practice for this key to be a number.



    So by having member_id in Members, group_id in Groups, you can create a many to many relationship in GroupMembers. Also, put a unique index on this table so you don't have duplicates ( the same member associated to the same id several times ).



    Look at this example linking users to roles. It is the same case:
    enter image description here






    share|improve this answer






























      2














      The problem is that



      CONSTRAINT iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name);
      references the table Members on the group_name field.



      This means that the field is_group on the table GroupMembers must have an identical value on the table Members and group_name field.



      In my opinion this is bad practice.
      First of all you should have a primary key field on the table GroupMembers. You should not store the names of the group members in the table GroupMembers, but their corresponding id from the table Members.



      Also the table Members, should look something like this:



          CREATE TABLE Members (
      member_id NUMBER PRIMARY KEY
      member_name VARCHAR2(40),
      CONSTRAINT g_id_pk PRIMARY KEY(member_id),
      CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


      Then on the table GroupMembers, I suppose you want to associate some members to their set of groups and back, so you should do something like this:



          CREATE TABLE GroupMembers (
      member_id NUMBER,
      group_id NUMBER
      )
      CONSTRAINT iam_is_member_fk FOREIGN KEY(member_id) REFERENCES Members(member_id);
      CONSTRAINT iam_is_member_fk FOREIGN KEY(group_id) REFERENCES Groups(group_id);


      Supposing that you have a table Groups containing all the group details, with the primary key stored as number , and name group_id.



      Always remeber that each table must have a primary key. It is good practice for this key to be a number.



      So by having member_id in Members, group_id in Groups, you can create a many to many relationship in GroupMembers. Also, put a unique index on this table so you don't have duplicates ( the same member associated to the same id several times ).



      Look at this example linking users to roles. It is the same case:
      enter image description here






      share|improve this answer




























        2












        2








        2







        The problem is that



        CONSTRAINT iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name);
        references the table Members on the group_name field.



        This means that the field is_group on the table GroupMembers must have an identical value on the table Members and group_name field.



        In my opinion this is bad practice.
        First of all you should have a primary key field on the table GroupMembers. You should not store the names of the group members in the table GroupMembers, but their corresponding id from the table Members.



        Also the table Members, should look something like this:



            CREATE TABLE Members (
        member_id NUMBER PRIMARY KEY
        member_name VARCHAR2(40),
        CONSTRAINT g_id_pk PRIMARY KEY(member_id),
        CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


        Then on the table GroupMembers, I suppose you want to associate some members to their set of groups and back, so you should do something like this:



            CREATE TABLE GroupMembers (
        member_id NUMBER,
        group_id NUMBER
        )
        CONSTRAINT iam_is_member_fk FOREIGN KEY(member_id) REFERENCES Members(member_id);
        CONSTRAINT iam_is_member_fk FOREIGN KEY(group_id) REFERENCES Groups(group_id);


        Supposing that you have a table Groups containing all the group details, with the primary key stored as number , and name group_id.



        Always remeber that each table must have a primary key. It is good practice for this key to be a number.



        So by having member_id in Members, group_id in Groups, you can create a many to many relationship in GroupMembers. Also, put a unique index on this table so you don't have duplicates ( the same member associated to the same id several times ).



        Look at this example linking users to roles. It is the same case:
        enter image description here






        share|improve this answer















        The problem is that



        CONSTRAINT iam_is_group_fk FOREIGN KEY(is_group) REFERENCES Members(group_name);
        references the table Members on the group_name field.



        This means that the field is_group on the table GroupMembers must have an identical value on the table Members and group_name field.



        In my opinion this is bad practice.
        First of all you should have a primary key field on the table GroupMembers. You should not store the names of the group members in the table GroupMembers, but their corresponding id from the table Members.



        Also the table Members, should look something like this:



            CREATE TABLE Members (
        member_id NUMBER PRIMARY KEY
        member_name VARCHAR2(40),
        CONSTRAINT g_id_pk PRIMARY KEY(member_id),
        CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(artistic_name));


        Then on the table GroupMembers, I suppose you want to associate some members to their set of groups and back, so you should do something like this:



            CREATE TABLE GroupMembers (
        member_id NUMBER,
        group_id NUMBER
        )
        CONSTRAINT iam_is_member_fk FOREIGN KEY(member_id) REFERENCES Members(member_id);
        CONSTRAINT iam_is_member_fk FOREIGN KEY(group_id) REFERENCES Groups(group_id);


        Supposing that you have a table Groups containing all the group details, with the primary key stored as number , and name group_id.



        Always remeber that each table must have a primary key. It is good practice for this key to be a number.



        So by having member_id in Members, group_id in Groups, you can create a many to many relationship in GroupMembers. Also, put a unique index on this table so you don't have duplicates ( the same member associated to the same id several times ).



        Look at this example linking users to roles. It is the same case:
        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 17:59









        Michu93

        93911233




        93911233










        answered Nov 22 '12 at 18:41









        ionutabionutab

        300216




        300216

























            0














            error is
            you have to use same column name which is defined in reference table



            i.e



            CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(group_name)



            That group_name should be define as primary key in Artist Table.






            share|improve this answer


























            • No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

              – b.enoit.be
              Feb 2 '15 at 13:05
















            0














            error is
            you have to use same column name which is defined in reference table



            i.e



            CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(group_name)



            That group_name should be define as primary key in Artist Table.






            share|improve this answer


























            • No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

              – b.enoit.be
              Feb 2 '15 at 13:05














            0












            0








            0







            error is
            you have to use same column name which is defined in reference table



            i.e



            CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(group_name)



            That group_name should be define as primary key in Artist Table.






            share|improve this answer















            error is
            you have to use same column name which is defined in reference table



            i.e



            CONSTRAINT m_group_name_fk FOREIGN KEY(group_name) REFERENCES Artist(group_name)



            That group_name should be define as primary key in Artist Table.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 16:03









            Michu93

            93911233




            93911233










            answered Feb 2 '15 at 12:41









            srinathsrinath

            1




            1













            • No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

              – b.enoit.be
              Feb 2 '15 at 13:05



















            • No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

              – b.enoit.be
              Feb 2 '15 at 13:05

















            No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

            – b.enoit.be
            Feb 2 '15 at 13:05





            No, you don't, have a look at the accepted answer. Moreover, please use the code block in your answers.

            – b.enoit.be
            Feb 2 '15 at 13:05











            0














            Order in which you are insert is the reason for the error.



            Members(group_name) does not contain Goldfrat. If this is not true then it's not there in the table Artists.






            share|improve this answer


























            • I'm inserting that line after i insert everything else

              – AkshaiShah
              Nov 22 '12 at 18:29











            • Ah yes of course, i missed that completely

              – AkshaiShah
              Nov 22 '12 at 18:34
















            0














            Order in which you are insert is the reason for the error.



            Members(group_name) does not contain Goldfrat. If this is not true then it's not there in the table Artists.






            share|improve this answer


























            • I'm inserting that line after i insert everything else

              – AkshaiShah
              Nov 22 '12 at 18:29











            • Ah yes of course, i missed that completely

              – AkshaiShah
              Nov 22 '12 at 18:34














            0












            0








            0







            Order in which you are insert is the reason for the error.



            Members(group_name) does not contain Goldfrat. If this is not true then it's not there in the table Artists.






            share|improve this answer















            Order in which you are insert is the reason for the error.



            Members(group_name) does not contain Goldfrat. If this is not true then it's not there in the table Artists.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 17:48









            Michu93

            93911233




            93911233










            answered Nov 22 '12 at 18:27









            Shamis ShukoorShamis Shukoor

            2,06722131




            2,06722131













            • I'm inserting that line after i insert everything else

              – AkshaiShah
              Nov 22 '12 at 18:29











            • Ah yes of course, i missed that completely

              – AkshaiShah
              Nov 22 '12 at 18:34



















            • I'm inserting that line after i insert everything else

              – AkshaiShah
              Nov 22 '12 at 18:29











            • Ah yes of course, i missed that completely

              – AkshaiShah
              Nov 22 '12 at 18:34

















            I'm inserting that line after i insert everything else

            – AkshaiShah
            Nov 22 '12 at 18:29





            I'm inserting that line after i insert everything else

            – AkshaiShah
            Nov 22 '12 at 18:29













            Ah yes of course, i missed that completely

            – AkshaiShah
            Nov 22 '12 at 18:34





            Ah yes of course, i missed that completely

            – AkshaiShah
            Nov 22 '12 at 18:34


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13518246%2fviolated-parent-key-not-found-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?