ruby on rails - Column 'sender_id' cannot be null after db reset -


i trying fix few new errors occurred after did rake db:migrate:reset. have fixed of them, except one. custom inbox, after click send new message error:

mysql2::error: column 'sender_id' cannot null: insert messages (body, container, created_at, read_at, recepient_deleted, recepient_id, sender_deleted, sender_id, subject, updated_at) values ('test 1', 'draft', '2013-04-05 18:59:08', null, 0, 16, 0, null, 'test 1', '2013-04-05 18:59:08')

now background information. before did reset changed migration. maybe coming play?

original migration:

class createmessages < activerecord::migration     def         create_table :messages |t|             t.string :sender_id,:null => false             t.string :recepient_id             t.boolean :sender_deleted, :recepient_deleted, :default => false             t.string :subject,:null => false             t.text :body             t.datetime :read_at             t.string :container,:default => "draft"             t.timestamps         end     end      def down         drop_table :messages     end end 

modified migration can change string integer:

class changesenderidandrecepientidcolumns < activerecord::migration   def change     change_column :messages, :sender_id, :integer     change_column :messages, :recepient_id, :integer   end    def down      change_column :messages, :sender_id, :string      change_column :messages, :recepient_id, :string   end end 

messages controller:

  def create     @message = message.new(params[:message])     @message.sender_id = @user_id     if @message.save       flash[:notice] = "message has been sent"       redirect_to user_messages_path(current_user, :mailbox=>:inbox)     else       render :action => :new     end   end 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -