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 7601443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:09:54+00:00 2026-05-30T23:09:54+00:00

If you use RedBean ORM, do you need to add a primary key named

  • 0

If you use RedBean ORM, do you need to add a primary key named “id” to every table in your database?

In my db I have a few tables that have primary keys pairs of 2 or 3 fields, or primary keys with other names than “id” (yes, I could change the name to “id”, but it wouldn’t really reflect the reality, because they are not IDs)

Example:

table1 – stores posts:

  id           INTEGER      PRIMARY KEY AUTOINCREMENT,
  name         TEXT,
  title        TEXT,
  content      TEXT,

table2 – stores meta for posts:

  post         INTEGER      DEFAULT 0,     # <- references "id" from "posts"
  name         TEXT,
  value        TEXT,
  PRIMARY KEY(name, post),
  CONSTRAINT posts_meta FOREIGN KEY(post)
    REFERENCES posts(id) ON DELETE CASCADE ON UPDATE RESTRICT

Would RedBean work with this kind of db structure?

  • 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-30T23:09:55+00:00Added an answer on May 30, 2026 at 11:09 pm

    Unfortunately, with how your current table structure is, you couldn’t use RedBean. Every table needs to have an auto-increment primary key. A slight downfall, as it makes integration into an already existing product more difficult.

    A couple of threads that failed to use RedBean due to this constraint, with responses from the author, Gabor De Mooij:

    http://groups.google.com/group/redbeanorm/browse_thread/thread/6d5582275326744f?pli=1

    http://groups.google.com/group/redbeanorm/browse_thread/thread/4fa7b29b453dcdb8

    RedBean does NOT require the primary key field to be named simply “id”, however. You can format the name of the primary key column to your liking by using the formatBeanID() method, as seen in the example below, which prefixes the table name to the “id” conditionally. eg) table users would have the primary key be users_id. Using that formatting, you can get as detailed with the id name as needed.

    http://redbeanphp.com/community/wiki/index.php/Prefixes

    Hopefully this restraint will be lifted in the future, since it really does hamper the integration into existing products.

    EDIT: As an alternative ORM, I’ve heard well of Doctrine: http://www.doctrine-project.org/. I haven’t personally used it, but it seems to be the standard for many working with PHP.

    EDIT 2: Thanks and credit to Jason for bringing to attention a new method for integrating RedBean into an existing project where your database might not be set up for it. I wanted to update my answer as well in case people still reference it with this problem. Gabor suggested making views that map to the tables, where you can set up the view to have the proper structure required for RedBean. I have not personally tested this, but it has gotten positive feedback from some users. It adds some extra overhead and maintenance when altering tables, but seems to be the best and most complete answer to this issue to date.
    http://www.redbeanphp.com/faq#beanformatter

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

Sidebar

Related Questions

In my new project, I decided that I will use the RedBean ORM system
USE master GO DECLARE @DbName nvarchar(MAX) SET @DbName = N'DataBase' ALTER DATABASE @DbName SET
Use Elixir and have two entities -- Voter and Candidate -- with many to
use javascript or other method ? have any recommendation?
use case example I have a servlet that is receiving login requests. If a
Use case: we have some project meta-data files which we want tracked, but are
Use of || (or) I got so many values which I need to compare
Hi I am just beginning to use redbeans ORM. I followed the docs and
Use Flex 4.5.1 and when add icons to the button is so curve effect
USE [Fk_Test2] GO /****** Object: Table [dbo].[Owners] Script Date: 08/20/2010 16:52:44 ******/ SET ANSI_NULLS

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.