yogthos / migratus-lein

27 stars 22 forks source link

Table "GUESTBOOK" not found #16

Open ILoveHubGit opened 8 years ago

ILoveHubGit commented 8 years ago

I'm trying to get the clojure application "guestbook" working. But when I run the application and browse to it at localhost:3000 I get an error:

org.h2.jdbc.JdbcSQLException at / Table "GUESTBOOK" not found; SQL statement: SELECT * FROM guestbook [42102-192]

I think something during "lein run migrate" is not working. The output I get from this is:

read config from resource: "config.edn" read config from file: ".lein-env" 2016-09-12 21:34:43,273 [main] INFO migratus.core - Starting migrations 2016-09-12 21:34:43,328 [main] INFO migratus.database - creating migration table 'schema_migrations' 2016-09-12 21:34:43,348 [main] INFO migratus.core - Ending migrations

I thought I've seen somewhere that it should give information about the tables as well, but I can't find it anymore

Please help

jeddahbill commented 7 years ago

I've been trying to work my way through Web Development with Clojure 2nd edition, and I have this same problem precisely. Of course continuing beyond this point in the book leads to other problems, i.e., (get-messages) invocation failing, but I suspect this database migration problem is the root cause of the troubles.

I read your thread with yogthos on the luminus-framework Bountysource forum with great interest, and noticed that it is listed as closed, without any definitive resolution. (https://www.bountysource.com/issues/37840182-table-guestbook-not-found)

I've been running Ubuntu 16.04 at first, but very recently upgraded to 16.10. I was hoping this upgrade might help but the behavior - as far as I've checked - is identical to before.

I would like to hear if you've made any progress on this problem.
If I do, I'll post whatever I find out here.

kucerm2 commented 7 years ago

I have the same problem on W10, the solution was to rewrite table name to uppercase in queries.sql.

-- :name save-message! :! :n
-- :doc creates a new message
INSERT INTO QUESTBOOK
(name, message, timestamp)
VALUES (:name, :message, :timestamp)

-- :name get-messages :? :*
-- :doc selects all available messages
SELECT * FROM QUESTBOOK
Futurile commented 7 years ago

I had the same problem, and am also working through "Web Development with Clojure 2nd edition".

It specifically asks you to set the luminus template to version 2.9.10.74 so that you get the same version as the book was written against. By adding this to ~/.lein/profiles.clj

{:user {:plugins [[luminus/lein-template "2.9.10.74]]}}

This in turn means that the the project.clj dependencies are:

    [luminus-migrations "0.2.2"]

As I haven't use luminus-migrations for anything else this means it has 0.2.2 in ~/.m2/repository/luminus-migrations/luminus-migrations

A default migration file is created in guestbook/resources/migrations/<timestamp>-guestbook-up.sql and I edited this by adding the guestbook table. But, for some reason, this migration is completely ignored.

lein run migrate 20170812092610
[2017-08-13 12:32:08,219][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-08-13 12:32:09,642][INFO][migratus.core] Starting migrations
[2017-08-13 12:32:10,076][INFO][migratus.core] Ending migrations
steve@lenovosg:~/workspace/webdev-clojure/first-app/guestbook$ lein run migrate
[2017-08-13 12:36:51,723][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-08-13 12:36:53,284][INFO][migratus.core] Starting migrations
[2017-08-13 12:36:53,748][INFO][migratus.core] Ending migrations

If you try to roll it back you get::

lein run rollback
[2017-08-13 12:19:19,066][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-08-13 12:19:20,567][INFO][migratus.core] Starting migrations
[2017-08-13 12:19:21,034][INFO][migratus.core] Running down for [20170812092610]
[2017-08-13 12:19:21,037][INFO][migratus.core] Down 20170812092610-add-users-table
[2017-08-13 12:19:21,047][DEBUG][migratus.database] found 1 down migrations
[2017-08-13 12:19:21,063][INFO][migratus.core] Ending migrations
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Table "GUESTBOOK" not found; SQL statement:
DROP TABLE guestbook;

For whatever reason it is completely ignoring the migration.

I tried renaming guestbook->GUESTBOOK but that didn't work for me.

Instead, I created a new migration file and put the SQL statements in there - that worked:

$ lein migratus create
$ mv 20170813124558-.up.sql 20170813124558-guestbook.up.sql
$  mv 20170813124558-.down.sql 20170813124558-guestbook.down.sql
# add the SQL statements to the file

Then when it's run you get real output:

steve@lenovosg:~/workspace/webdev-clojure/first-app/guestbook/resources/migrations$ lein run migrate
[2017-08-13 12:51:54,149][DEBUG][org.jboss.logging] Logging Provider: org.jboss.logging.Log4jLoggerProvider
[2017-08-13 12:51:55,751][INFO][migratus.core] Starting migrations
[2017-08-13 12:51:56,199][INFO][migratus.core] Running up for [20170813124558]
[2017-08-13 12:51:56,202][INFO][migratus.core] Up 20170813124558-guestbook
[2017-08-13 12:51:56,213][DEBUG][migratus.database] found 1 up migrations
[2017-08-13 12:51:56,249][DEBUG][migratus.database] marking 20170813124558 complete
[2017-08-13 12:51:56,262][INFO][migratus.core] Ending migrations

After that I'm able to connect to the database and carry on ...

curtiswallen commented 7 years ago

I'm having this exact same problem. Have tried all suggestions in this thread to no avail. Hoping someone has some new thoughts?

macOS 10.12.6