New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running SQLite example fails #822

Closed
palango opened this Issue Mar 22, 2017 · 10 comments

Comments

Projects
None yet
4 participants
@palango
Contributor

palango commented Mar 22, 2017

I'm trying to run the SQLite example in diesel/examples/sqlite. I adapted the test_all script to use the locally installed version, which is 0.12.

I get the following compiler errors and would be interested in any hints...

$ ./test_all_2
Dropping database: /tmp/test_examples.db
Creating database: /tmp/test_examples.db
Running migration 20170124012402
   Compiling diesel_demo_step_1_sqlite v0.1.0 (file:///Users/paul/Projects/rust/crates/diesel/examples/sqlite/getting_started_step_1)
error[E0432]: unresolved import `self::schema::posts::dsl::*`
 --> src/bin/show_posts.rs:9:9
  |
9 |     use self::schema::posts::dsl::*;
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `posts` in `schema`

error[E0425]: cannot find value `posts` in this scope
  --> src/bin/show_posts.rs:12:19
   |
12 |     let results = posts.filter(published.eq(true))
   |                   ^^^^^ not found in this scope

error[E0425]: cannot find value `published` in this scope
  --> src/bin/show_posts.rs:12:32
   |
12 |     let results = posts.filter(published.eq(true))
   |                                ^^^^^^^^^ not found in this scope

error: aborting due to 3 previous errors

error: Could not compile `diesel_demo_step_1_sqlite`.

To learn more, run the command again with --verbose.
@Eijebong

This comment has been minimized.

Member

Eijebong commented Mar 22, 2017

I think you didn't run the migrations so the database doesn't exist and diesel cannot infer the schema

@palango

This comment has been minimized.

Contributor

palango commented Mar 22, 2017

I think you didn't run the migrations so the database doesn't exist and diesel cannot infer the schema

Doesn't Running migration 20170124012402 mean that the migrations are run?

@Eijebong

This comment has been minimized.

Member

Eijebong commented Mar 22, 2017

Oh, missed that :p
I still think that the database is not in the correct state.
What did you change in the test_all script ?

@palango

This comment has been minimized.

Contributor

palango commented Mar 22, 2017

It looks like that (just removed the relative path from the diesel program:

#!/bin/sh
set -e

export DATABASE_URL="/tmp/test_examples.db"

for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
  cd $dir
  diesel database reset
  cargo build
  cd ..
done
@palango

This comment has been minimized.

Contributor

palango commented Mar 22, 2017

If I open the test_database.db file and look at the schema it looks right:

sqlite> .schema posts
CREATE TABLE posts (
  id INTEGER NOT NULL PRIMARY KEY,
  title VARCHAR NOT NULL,
  body TEXT NOT NULL,
  published BOOLEAN NOT NULL DEFAULT 0
);
@Eijebong

This comment has been minimized.

Member

Eijebong commented Mar 22, 2017

Do you have a .env file somewhere in there ?

@palango

This comment has been minimized.

Contributor

palango commented Mar 22, 2017

Do you have a .env file somewhere in there ?

No

@Eijebong

This comment has been minimized.

Member

Eijebong commented Mar 22, 2017

Weird then :( I don't have any more ideas maybe someone with more knowledge than me can help you, sorry

@ericho

This comment has been minimized.

Contributor

ericho commented Mar 25, 2017

I can reproduce this (and possibly fix). If DATABASE_URL is not set, then you will see the error and you'll see it all the next times you run cargo build, without matter if DATABASE_URL is set or not.

Try to run a cargo clean before running the script again. That worked for me to solve the issue.

@palango

This comment has been minimized.

Contributor

palango commented Mar 25, 2017

That helped for me as well.

@sgrif sgrif closed this Dec 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment