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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:25:12+00:00 2026-05-27T12:25:12+00:00

\d users Table public.users Column | Type | Modifiers ————————+—————————–+—————————————————- id | integer |

  • 0

\d users

                                           Table "public.users"
         Column         |            Type             |                     Modifiers                      
------------------------+-----------------------------+----------------------------------------------------
 id                     | integer                     | not null default nextval('users_id_seq'::regclass)
 email                  | character varying(255)      | not null default ''::character varying
 encrypted_password     | character varying(128)      | not null default ''::character varying
 reset_password_token   | character varying(255)      | 
 reset_password_sent_at | timestamp without time zone | 
 remember_created_at    | timestamp without time zone | 
 sign_in_count          | integer                     | default 0
 current_sign_in_at     | timestamp without time zone | 
 last_sign_in_at        | timestamp without time zone | 
 current_sign_in_ip     | character varying(255)      | 
 last_sign_in_ip        | character varying(255)      | 
 created_at             | timestamp without time zone | 
 updated_at             | timestamp without time zone | 
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "index_users_on_email" UNIQUE, btree (email)
    "index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)

\d posts

                                   Table "public.posts"
   Column    |          Type          |                     Modifiers                      
-------------+------------------------+----------------------------------------------------
 id          | integer                | not null default nextval('posts_id_seq'::regclass)
 title       | character varying(100) | not null
 content     | character varying(500) | not null
 created_at  | date                   | 
 updated_at  | date                   | 
 tags        | character varying(55)  | not null default '50'::character varying
 category_id | integer                | not null default 1
Indexes:
    "posts_pkey" PRIMARY KEY, btree (id)

I need to keep track who is post a post, so i need username column in posts table.
Shoud i add a username column in posts table or should i add username in users table or should i create a different table for userdetails with username.

I also need to check whether the user is admin or normal user.

Can anyone post complete relational database schema for this purpose ?

devise User model

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

end
  • 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-27T12:25:13+00:00Added an answer on May 27, 2026 at 12:25 pm

    You don’t want a username in your posts table, you just want the user’s ID. The username would go in your users table.

    For your users table, you’d want this in the table creation:

    t.string, :username, :null => false
    

    and a :limit if you want to limit the length. Then in your User class:

    validates :username, :uniqueness => { :case_sensitive => false }
    has_many :posts
    

    If you don’t want usernames to be unique then you could drop the validates :username; you could also downcase the usernames in a before_validate hook and add a unique index on username to your users table. You might want some flags on the has_many, see the guide for details.

    Then, when creating posts:

    t.integer, :user_id, :null => false
    

    and in Post:

    belongs_to :user
    

    Then you can get the username for a post through its user:

    p.user.username
    

    If you’re trying to add usernames to existing data then you’d need :null => true in your migrations for the new columns and you’d have to figure out what you want to do with the missing values in your existing data.

    I don’t know how any of this would integrate with devise (sorry, I don’t use it) or if devise will even care about usernames. Hopefully someone else can fill in the devise parts (if any) and leave me a comment if they do.

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

Sidebar

Related Questions

My custom type is (no default constructor!): package com.XXX.common; public class Email implements Serializable
In PostgreSQL 8.4 I have a user table: # \d pref_users; Table public.pref_users Column
table: UserTypes Fields: row,name,Type This code is not working: Int64 row = 1; var
users table +-----+-----------+ | id | username | +-----+-----------+ | 1 | tom |
I have users table. There are three other tables: developers, managers, testers. All of
i have users table and i have posts table i want select from users
I'm trying to create a Users table that only has OpenId registrations, exactly like
I have a table called UserPermissions with a FK to the users table by
I want to add 100 entry to users table numbers field, random characters length
I have a items table with 1 million rows and a users table with

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.