@Mukund To answer your question:
Yes, I used db:migrate to build the database, then I used phpmyadmin
to see what the result was, I’m new to rails programming and thought
it would be useful to examine the result.
I think I have the connection to the database correct, the problem
appears (to me) to be in the setup before I migrate.
I’m doing the restful_authentication with all the bells & whistles
tutorial. I started over again to go from the beginning. When I get to
the migration I get an error, here’s the initial error and the full
trace:
ERROR:
== SetUpFirstAdminUser: migrating
rake aborted!
An error has occurred, all later migrations canceled:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.activated_at=
FULL TRACE:
(in /Users/Me/Sites/RAT2/restful_authentication_tutorial)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== SetUpFirstAdminUser: migrating
rake aborted!
An error has occurred, all later migrations canceled:
Mysql::Error: Duplicate entry ‘userDEV’ for key 2: INSERT INTO users
(name
, salt
, updated_at
, activated_at
, crypted_password
,
remember_token_expires_at
, activation_code
, password_reset_code
,
enabled
, invitation_id
, user_type
, remember_token
,
identity_url
, login
, email
, created_at
, invitation_limit
)
VALUES(’’, ‘1a9bde41a2d6d664d03e32676c479a07f301d2a6’, ‘2009-09-20
16:23:19’, NULL, ‘b984b8c4f7258b854fab69f85c8b2a95116b41c9’, NULL,
‘1194519fe5c980f38f0d8ffd77f2c8b94625af2b’, NULL, 1, NULL, ‘SiteUser’,
NULL, NULL, ‘userDEV’, NULL, ‘2009-09-20 16:23:19’, 5)
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
rows_logger/init.rb:36:in log' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb: 320:in
execute_without_analyzer’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
footnotes/lib/rails-footnotes/notes/queries_note.rb:104:in
execute_without_query_stats' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activesupport/lib/active_support/core_ext/benchmark.rb:10:in
realtime’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/
footnotes/lib/rails-footnotes/notes/queries_note.rb:104:in
execute_without_query_stats' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/ query_stats/lib/query_stats/recorder.rb:16:in
execute’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activesupport/lib/active_support/core_ext/benchmark.rb:10:in
realtime' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/plugins/ query_stats/lib/query_stats/recorder.rb:15:in
execute’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:259:in insert_sql' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/mysql_adapter.rb: 330:in
insert_sql’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:44:in insert_without_query_dirty' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/connection_adapters/abstract/ query_cache.rb:18:in
insert’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/base.rb:2902:in
create_without_timestamps' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/timestamp.rb:29:in
create_without_callbacks’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/callbacks.rb:266:in create' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/base.rb:2868:in
create_or_update_without_callbacks’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/callbacks.rb:250:in create_or_update' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/base.rb:2539:in
save_without_validation’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/validations.rb:1009:in
save_without_dirty' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/dirty.rb:79:in
save_without_transactions’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:229:in send' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:229:in
with_transaction_returning_status’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:136:in transaction' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:182:in
transaction’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:228:in
with_transaction_returning_status' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:196:in
save’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/transactions.rb:208:in
rollback_active_record_state!' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/transactions.rb:196:in
save’
./db/migrate//20080806025753_set_up_first_admin_user.rb:9:in
up_without_benchmarks' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:282:in
send’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:282:in migrate' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/benchmark.rb:293:in
measure’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:282:in migrate' (__DELEGATION__):2:in
send’
(DELEGATION):2:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:486:in
migrate’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:562:in call' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:562:in
ddl_transaction’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:485:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:472:in
each’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:472:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ activerecord/lib/active_record/migration.rb:400:in
up’
/Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/
activerecord/lib/active_record/migration.rb:383:in migrate' /Users/Me/Sites/RAT2/restful_authentication_tutorial/vendor/rails/ railties/lib/tasks/databases.rake:116 /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
call’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
each’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in
invoke_with_call_chain’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
1.8/monitor.rb:242:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
invoke_with_call_chain’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in
invoke_task’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
each’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in
run’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in
run’
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load’
/usr/bin/rake:19
Here’s my SetupFirstAdminUser file, should I change ‘settings’ in the
user.email line? What goes there?
class SetUpFirstAdminUser < ActiveRecord::Migration
def self.up
#Be sure to change these settings for your initial admin user
user = SiteUser.new
user.login = “userDEV”
user.email = APP_CONFIG[‘settings’][‘[email protected]’]
user.password = “mypassword”
user.password_confirmation = “mypassword”
user.save(false)
role = Role.new
#Admin role name should be “admin” for convenience
role.name = “admin”
role.save
admin_user = SiteUser.find_by_login(“admin”)
admin_role = Role.find_by_name(“admin”)
admin_user.activated_at = Time.now.utc
admin_user.roles << admin_role
admin_user.save(false)
end
def self.down
admin_user = User.find_by_login(“admin”)
admin_role = Role.find_by_name(“admin”)
admin_user.roles = []
admin_user.save
admin_user.destroy
admin_role.destroy
end
end