Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 403855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:15:17+00:00 2026-05-12T17:15:17+00:00

I was wondering if you can specify the order in which table definitions and

  • 0

I was wondering if you can specify the order in which table definitions and data fixtures are loaded using the CLI. My problem is that I have two tables, each having a foreign key constraint pointing to the other, so one of the constraints needs to be added after a record has been added. Or maybe there’s a better way of doing this…I’m no db expert and my head is fuzzy today.

Schema:

CREATE TABLE clients (
  id INT AUTO_INCREMENT,
  name VARCHAR(255), address VARCHAR(255), 
  primary_contact_user_id INT  # References a user record in the users table
  ...
);

CREATE TABLE users (
  id INT AUTO_INCREMENT,
  username VARCHAR(255),
  client_id INT  # References a client record in the clients table
  ...
);

ALTER TABLE clients 
  ADD CONSTRAINT clients_primary_contact_user_id_users_id 
    FOREIGN KEY (primary_contact_user_id) REFERENCES users(id);

ALTER TABLE users 
  ADD CONSTRAINT users_client_id_clients_id 
    FOREIGN KEY (client_id) REFERENCES clients(id);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:15:18+00:00Added an answer on May 12, 2026 at 5:15 pm

    I’m also not a DB expert, but I do spend a lot of time working with them. I believe the circular reference is actually incorrect.

    Regardless of whether DB theory sanctions it or not, you could get one field though a join to another table, so it is an unnecessary circular reference. I’d suggest that you eliminate one and alter any queries to reflect this change.

    Based on a guess, I’d suggest that you eliminate primary_contact_user_id, as that almost sounds like a possible many-to-many relationship where a single item is elected as “primary”…

    If you feel this design is necessary, can you please explain why?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how can I specify the method to send the data from
I have a config file that the user can specify sections, and then within
I'm wondering how can I submit a form via Ajax (using prototype framework) and
I was wondering how can I validate a single checkbox using PHP and MySQL.
I'm wondering how can I write a function: 'a list*int -> 'a list*list that
I am just wondering how I can specify a dynamic url for an image
I was wondering how I can specify the size of cache in Android emulator?
I have a requirement whereby a user can specify a variable number of user-defined
I'm wondering how can I find these records using the CActiveRecord / CDbCriteria in
I have a java program which is using the default XML logging as no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.