OpenWISP-Manager icon indicating copy to clipboard operation
OpenWISP-Manager copied to clipboard

Error running rake:db:migrate

Open ndarilek opened this issue 10 years ago • 1 comments

Getting the following with master under MySQL 5.7:

== CreateL2vpnTemplates: migrating =========================================== -- create_table(:l2vpn_templates) rake aborted! An error has occurred, all later migrations canceled:

Mysql::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE l2vpn_templates (id int(11) DEFAULT N ULL auto_increment PRIMARY KEY, notes text, access_point_template_id int(11) , l2vpn_server_id int(11), created_at datetime, updated_at datetime) ENGIN E=InnoDB

Tasks: TOP => db:migrate (See full trace by running task with --trace)

Looks like a library is generating faulty SQL, especially since your migrations don't explicitly create the id column. This is a fairly standard Dockerized install. The following Dockerfile should replicate the problem, especially if you connect it with the official mysql:5.7 image:

FROM ubuntu:12.04 RUN apt-get update &&
apt-get upgrade -y &&
apt-get install -y git make ruby-dev rubygems libmysqlclient-dev libarchive-dev libbz2-dev libsqlite3-dev &&
apt-get clean &&
gem install bundler &&
cd /usr/src &&
git clone https://github.com/openwisp/OpenWISP-Manager app &&
cd app &&
bundle install --deployment &&
adduser --system --group --sh /bin/sh app &&
chown -R app.app /usr/src/app/log /usr/src/app/tmp ADD database.yml /usr/src/app/config/database.yml WORKDIR /usr/src/app USER app ENV RAILS_ENV production

If you can't explicitly run Docker, hopefully the above commands provide enough context to duplicate the issue.

As a fix, would it be possible to check in a db/schema.rb from the latest version so we can directly import the newest schema without running all the migrations? (assuming, that is, the same library isn't generating the schema and wouldn't also generate bad ids. :)

Thanks.

ndarilek avatar Nov 09 '14 03:11 ndarilek

OK, resolved this. Apparently Rails migrations don't work under MySQL 5.7. This was fixed, but presumably in a newer version of Rails than you're using.

Wonder if it might be worth a note in the readme, particularly as you're on an old Rails? I'll leave this issue open in case that's something you want to do.

Thanks.

ndarilek avatar Nov 09 '14 03:11 ndarilek