简体   繁体   中英

Rails Migration doesn't create anything

I'm currently on section 8.2.1 of Michael Hartl's rails tutorial. I'm currently trying to add a remember_token to my Users model to keep track of sessions.

When I run 'rails generate migration add_remember_token_to_users', the database does not get updated and no files are created in db/migrate

This is what I get when I run 'rails generate migration add_remember_token_to_users'

C:\Sites\sample_app>rails generate migration add_remember_token_to_users
DL is deprecated, please use Fiddle
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby bina
ry of your choice
                                                         # Default: C:/RailsInst
aller/Ruby2.0.0/bin/ruby.exe
  -m, [--template=TEMPLATE]                              # Path to some applicat
ion template (can be a filesystem path or URL)
      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfil
e
  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle inst
all
  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .
keep files
  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record fi
les
  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files
  -d, [--database=DATABASE]                              # Preconfigure for sele
cted database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserv
er/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                         # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]                          # Preconfigure for sele
cted JavaScript library
                                                         # Default: jquery
  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files

      [--dev], [--no-dev]                                # Setup the application
 with Gemfile pointing to your Rails checkout
      [--edge], [--no-edge]                              # Setup the application
 with Gemfile pointing to Rails repository
  -T, [--skip-test-unit], [--no-skip-test-unit]          # Skip Test::Unit files

      [--rc=RC]                                          # Path to file containi
ng extra configuration options for rails command
      [--no-rc], [--no-no-rc]                            # Skip loading of extra
 configuration options from .railsrc file

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

Rails options:
  -h, [--help], [--no-help]        # Show this help message and quit
  -v, [--version], [--no-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.

edit: result from running 'dir'

C:\Sites\sample_app>dir
 Volume in drive C is Windows8_OS
 Volume Serial Number is 02F6-CD19

 Directory of C:\Sites\sample_app

08/04/2014  11:15 PM    <DIR>          .
08/04/2014  11:15 PM    <DIR>          ..
08/04/2014  07:49 PM                 0 -e
07/06/2014  07:23 PM    <DIR>          .bundle
07/06/2014  07:19 PM               466 .gitignore
07/06/2014  07:32 PM                 8 .rspec
07/06/2014  07:32 PM               128 .secret
08/04/2014  11:15 PM    <DIR>          app
08/03/2014  07:50 PM    <DIR>          config
07/06/2014  07:19 PM               154 config.ru
08/04/2014  08:25 PM    <DIR>          db
07/06/2014  07:21 PM             1,287 Gemfile
07/06/2014  07:23 PM             5,085 Gemfile.lock
07/06/2014  07:19 PM             1,171 Gemfile~
07/06/2014  07:19 PM    <DIR>          lib
07/06/2014  08:03 PM    <DIR>          log
07/06/2014  07:19 PM    <DIR>          public
07/06/2014  07:19 PM               254 Rakefile
07/06/2014  07:33 PM               185 README.md
07/06/2014  07:19 PM               478 README.rdoc~
08/02/2014  05:03 PM    <DIR>          spec
07/06/2014  07:59 PM    <DIR>          tmp
07/06/2014  07:19 PM    <DIR>          vendor
              11 File(s)          9,216 bytes
              12 Dir(s)  883,421,155,328 bytes free

By the looks of the error your getting, your not actually in a rails project directory

Try running the same rails generate command when you are at the root of your rails project

EDIT

Try adding a folder called

script

to your rails root as Vasseurth linked to

in this folder add a file called

rails

and add to it

APP_PATH = File.expand_path('../../config/application',  __FILE__)
require File.expand_path('../../config/boot',  __FILE__)
require 'rails/commands'

If you are infact inside your rails project directory, take a look at this question. It is nearly exactly the same as yours with a solution to being inside the directory and still receiving this error.

It turns out that I misplaced my bin folder. It was contained within my 'app' folder. I cut/pasted my bin folder back into the app's root directory, and now the migration works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM