ga-wdi-boston / full-stack-project

Other
8 stars 64 forks source link

Broke server? #1019

Closed CoreyFedde closed 7 years ago

CoreyFedde commented 7 years ago

Just an ordinary day of running a migration that failed which now is causing 500 internal server errors. (POST http://localhost:4741/sign-in/ 500 (Internal Server Error))

I created a migration to change a column in my database to not accept null data. When I ran it I got the error message below. Now I'm getting 500 server errors when trying to log in. Currently troubleshooting, but open to suggestions:

$ bin/rails db:migrate == 20170725134013 ChangeTitleNullFalse: migrating ============================= -- change_column_null(:movies, :title, false) rails aborted! StandardError: An error has occurred, this and all later migrations canceled:

PG::NotNullViolation: ERROR: column "title" contains null values : ALTER TABLE "movies" ALTER "title" SET NOT NULL /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/db/migrate/20170725134013_change_title_null_false.rb:3:in change' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:inrequire' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:in <top (required)>' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/spring:15:in<top (required)>' bin/rails:3:in load' bin/rails:3:in

' ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: column "title" contains null values : ALTER TABLE "movies" ALTER "title" SET NOT NULL /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/db/migrate/20170725134013_change_title_null_false.rb:3:in change' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:inrequire' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:in <top (required)>' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/spring:15:in<top (required)>' bin/rails:3:in load' bin/rails:3:in
' PG::NotNullViolation: ERROR: column "title" contains null values /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/db/migrate/20170725134013_change_title_null_false.rb:3:in change' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:inrequire' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/rails:9:in <top (required)>' /Users/coreyfedde/wdi/projects/movie-list-project/movie-list-backend/bin/spring:15:in<top (required)>' bin/rails:3:in load' bin/rails:3:in
' Tasks: TOP => db:migrate (See full trace by running task with --trace)

cpearce31 commented 7 years ago

Is it possible that the column you modified already had some null entries in it? Because Rails wouldn't like that.

CoreyFedde commented 7 years ago

Yes, there are entries in that column will null entries.

cpearce31 commented 7 years ago

I believe you'll need to get rid of those before that migration can be successful.

CoreyFedde commented 7 years ago

The root of the problem was the server was not running while a migration was pending. After clearing the table of null values and running db:migrate, the problem was fixed.

Thanks, Caleb