title: Primary or unique constraint required on main table: "Orders"
body: <p>Sorry if the title is unclear.</p>
  <p>As of right now, I just have a spreadsheet of a bunch of customers and orders. For example, a line in the spreadsheet might look like:</p>
  <p>A Customer with an ID of <code>1</code> with name <code>Sally</code> and address <code>291 North Street</code> bought item id 2.</p>
  <p>The actual spreadsheet looks something like this table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Customer Id</th>
  <th>Customer Name</th>
  <th>Customer Address</th>
  <th>Item Id</th>
  <th>Name</th>
  <th>Cost</th>
  <th>Order Id</th>
  <th>Ordered Date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Sally</td>
  <td>291 North Street</td>
  <td>2</td>
  <td>Long Sleeves</td>
  <td>$20</td>
  <td>1</td>
  <td>1/1/2022</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Sally</td>
  <td>291 North Street</td>
  <td>1</td>
  <td>Shirt</td>
  <td>$15</td>
  <td>1</td>
  <td>1/1/2022</td>
  </tr>
  <tr>
  <td>2</td>
  <td>George</td>
  <td>892 Lakers Ave</td>
  <td>3</td>
  <td>Backpack</td>
  <td>$30</td>
  <td>5</td>
  <td>4/9/2022</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My goal is to properly normalize this data so it's not as redundant. I've already separated the data into 3 tables, <code>Items</code>, <code>Orders</code>, and <code>OrderInfo</code>.</p>
  <p>Items follows a structure like so:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Item Id (PK)</th>
  <th>Name</th>
  <th>Cost</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>XL Shirt</td>
  <td>$15</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Long sleeves shirt</td>
  <td>$20</td>
  </tr>
  <tr>
  <td>3</td>
  <td>Backpack</td>
  <td>$30</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Orders:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Order ID (PK/FK?)</th>
  <th>Customer ID</th>
  <th>Ordered Date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  <td>1/1/2022</td>
  </tr>
  <tr>
  <td>5</td>
  <td>2</td>
  <td>4/9/2022</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>OrderInfo:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Order ID (PK/FK?)</th>
  <th>Item ID (PK/FK?)</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2</td>
  </tr>
  <tr>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>5</td>
  <td>3</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>As you can see from the orders table, I tried to combine all redundant orders where say user Sally ordered a long sleeves shirt and a regular shirt in the same order. However, this leaves redundant data in the OrdersInfo table, where the OrderId is the same for multiple fields because the customer bought multiple items in one order.</p>
  <p>Is this correct? I am trying to define relationships on the tables in LibreOffice Base, and I can define the correct one-to-many relationships for all of them except for OrderInfo and Orders.</p>
  <p>Here's a screenshot of the relations and the error when I try to link the OrderID field.</p>
  <p><a href="https://i.stack.imgur.com/1fU1u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fU1u.png" alt="Relations" /></a></p>
  <p><a href="https://i.stack.imgur.com/lvzpE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lvzpE.png" alt="Error" /></a></p>
  <p>Error code:</p>
  <pre><code>SQL Status: S0011
  Error code: -170
  
  Primary or unique constraint required on main table: &quot;Orders&quot; in statement [ALTER TABLE &quot;Order_Info&quot; ADD  FOREIGN KEY (&quot;order_id&quot;) REFERENCES &quot;Orders&quot; (&quot;order_id&quot;)]
  </code></pre>