PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

[FIXED] How to generate a model after running a migration on rails

 April 14, 2022     migration, ruby-on-rails     No comments   

Issue

I have created a migration file as follows before generating a model , viewer or a controller

class Papaers < ActiveRecord::Migration
  def self.up
   create_table :papers do |t|
   t.integer :unit_id, :null=>false
   t.integer :document_id, :null=>false
   t.timestamps
 end
end

 def self.down
   drop_table :papers
 end
end

This ran well and it create the table. But now I want to create a model for this table. Is there a way in rails to create a model after running migration files? I could not see any model generated under papers in model.


Solution

rails g model Papaers --migration=false

Or you can also give

rails g model Papaers

Rails generator would not overwrite if migration already exists.



Answered By - Siva
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing