Foreign keys are almost always “Allow Duplicates,” which would make them unsuitable as Primary Keys.
Instead, find a field that uniquely identifies each record in the table, or add a new field (either an auto-incrementing integer or a GUID) to act as the primary key.
The only exception to this are tables with a one-to-one relationship, where the foreign key and primary key of the linked table are one and the same.
Related Posts:
- Can I have multiple primary keys in a single table?
- What’s the simplest way to backup my WordPress database?
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- Fastest way (least amount of steps) to locally import a remote database using WP-CLI
- Solution for database version control and deployment?
- How to integrate custom database table in WordPress and using WordPress functions
- Slow wp_term_relationships query
- delete_option() and update_option() returning false
- How to change option recently_edited?
- How to initialize $wpdb?
- Organizing WP Pages based on old website database
- When importing database, it shows error
- How to close wpdb connection? [duplicate]
- Why is Woocommerce writing in my wp_comment table?
- save new data to wp_options non-post form
- Error establishing a database connection when migrating site to localhost
- How to implement content from external database into WordPress text page? [closed]
- Strange characters on wordpress site – Not UTF8 Issue
- WordPress showing install screen after max_questions error
- Connect to live db whilst working locally
- Storing textbox values in Database
- WooCommerce – Query for ordered products
- Insert custom data to custom table on wordpress database
- How does WordPress store data?
- Query WordPress database by registered date and role
- Tons of Twitter rows in my database
- Merging WordPress posts from different databases
- Why can’t I swap a DB in a WP install? [closed]
- How to replace values in WordPress DB using phpMyAdmin
- How do I reset a self-hosted WordPress URL?
- Show content from database
- Customize JSON output
- CRUD operations using WordPress database API
- Display SQL that wordpress is running
- Critical error in final stage of website launch – URLs are BROKEN!
- change wp user status from wp_users table
- How to resolve Connections using insecure transport are prohibited while –require_secure_transport=ON
- How to Mirror WordPress database from Remote server to Local server
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Difficulty importing my live site to local
- WordPress returns to an old version
- data (html) migration to posts
- Super slow queries from author archive pages killing my database
- localize elements in database
- How to fix database error duplicate entry
- Use same database on main domain & sub domain
- WPDB SQL query with prepare() returning variable, not db value
- Get value form wordpress database
- Moving to another server database connection error [closed]
- Best practice to limit results in get_row()?
- How to display content from external db with relevant urls
- Is there an easy way of exporting posts with their category already asigned and pictures from localhost?
- Connect to another WP install and grab post based on custom field
- Which table (and column) has the content of configured get_post_meta?
- Serialize data before inserting into the DB
- Reinstalling wordpress from database breaks the site
- Pages from custom table
- Trouble running $wpdb->query() with last_insert_id
- content disappearing minutes after it’s published
- What is the most efficient way to reset a WordPress site?
- Add pdf to a website
- Optimizing function that automatically creates internal links based on post title string
- Can I customised default WP table
- Woocommerce – Check product stock availability from external database
- Get results from wordpress data custom table
- WordPress where clauses in db select
- How to display data from db in select list [closed]
- Will adding & modifying default WordPress table index break future WordPress update
- Database migration issues – Error #1046 No database selected
- echo site_url() returns a different value than what is in the database siteurl field
- Native timestamp on wp_options option
- _wp_attachment_metadata is not being added to database when PDF files uploaded
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to get the full stack trace for WordPress “table doesn’t exist” error in debug.log?
- How to access a table in a wordpress database using REST API?
- How do I loop/iterate through posts to edit all img tags?
- error establishing a database connection 3
- How to edit posts/pages without making the change live?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to optimise this database query?
- How to retrieve user data based on role using SQL?
- Does WordPress Support Using Named Pipes on the Windows Operating System?
- Missing latest posts and options after DB migration via phpMyAdmin
- Split database on large site?
- Store the wordpress “featured image” under »wp_posts« Database table
- Custom metabox does not store data
- wordpress database error
- How do i get value from wp_postmeta?
- Local host to server import problem
- Restoring .sql backup results in “Error establishing a database connection”
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect
- Getting deleted users in database
- Options of accessing wordpress data from mobile app
- Getting data from a table using a query
- Database interaction (private-public) [closed]
- wp-config was suddenly updated
- Weird WP -Cli Error Connection Refused
- Order of search results based off of a backend custom field and also in alpha order
- How to find fresh (last modified) and sql backup?