質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
mysqli

MySQLiはPHP5より導入されているデータベース用のドライバです。MySQL 4.1.3以降の新しい機能の利点をまとめています。

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Q&A

0回答

819閲覧

Rails g migrationコマンドでカラムの追加が反映されていない?

suirunakamura

総合スコア16

mysqli

MySQLiはPHP5より導入されているデータベース用のドライバです。MySQL 4.1.3以降の新しい機能の利点をまとめています。

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

0グッド

0クリップ

投稿2020/07/30 14:43

編集2020/08/04 06:14

rails g modelコマンドを実行しモデルとマイグレーションファイルを作成し、作成したマイグレーションファイルに追加したいカラムを追記し、rails g migrationコマンドを実行しました。
下記のコードは、作成したマイグレーションファイルにカラムを追加する記述と、ターミナルでのrails g migrationコマンドを実行したものです。

class CreateArticles < ActiveRecord::Migration[6.0] def change create_table :articles do |t| t.date :dating t.string :title t.text :text t.timestamps end end end
rooter:portfolio apple$ rails g migration Running via Spring preloader in process 6990 Usage: rails generate migration NAME [field[:type][:index] field[:type][:index]] [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications) -o, --orm=NAME # ORM to be invoked # Default: active_record ActiveRecord options: [--primary-key-type=PRIMARY_KEY_TYPE] # The type for primary key --db, [--database=DATABASE] # The database for your migration. By default, the current environment's primary database is used. Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Description: Stubs out a new database migration. Pass the migration name, either CamelCased or under_scored, and an optional list of attribute pairs as arguments. A migration class is generated in db/migrate prefixed by a timestamp of the current date and time. You can name your migration in either of these formats to generate add/remove column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable Example: `rails generate migration AddSslFlag` If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration db/migrate/20080514090912_add_ssl_flag.rb `rails generate migration AddTitleBodyToPost title:string body:text published:boolean` This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration: add_column :posts, :title, :string add_column :posts, :body, :text add_column :posts, :published, :boolean Migration names containing JoinTable will generate join tables for use with has_and_belongs_to_many associations. Example: `rails g migration CreateMediaJoinTable artists musics:uniq` will create the migration create_join_table :artists, :musics do |t| # t.index [:artist_id, :music_id] t.index [:music_id, :artist_id], unique: true end

どなたか、ご教授お願いします!

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問