Unknown type `unique` given to generator #1326

Closed
bigbassroller opened this Issue Oct 30, 2015 · 11 comments

Projects

None yet

7 participants

@bigbassroller

Hello,

Thanks for the awesome Phoenix project.

I am trying to use the unique type key to use for authenticating unique email addresses. I am running phoenix v1.0.3.

When running this example from https://github.com/phoenixframework/phoenix/blob/master/lib/mix/tasks/phoenix.gen.model.ex line 46:
mix phoenix.gen.model Post posts title:unique unique_int:integer:unique

I get this error:
** (Mix) Unknown typeuniquegiven to generator

It should be available, according to https://github.com/phoenixframework/phoenix/blob/master/lib/mix/tasks/phoenix.gen.model.ex line 46.

But if I go to my local copy of Phoenix, /deps/phoenix/lib/mix/tasks/phoenix.gen.model.ex there is no mention of the unique key.

What is up with that?

Cheers,
Mike

@Gazler
Member
Gazler commented Oct 30, 2015

Unique in the generator was added in this commit: 8758c5b (2 weeks ago, and there hasn't been a release since 1.0.3 4 weeks ago.)

It will only be available if you are using the master branch of phoenix.

@josevalim
Member

@Gazler is right. :)

@josevalim josevalim closed this Oct 30, 2015
@bigbassroller

Thanks for the reply. I got it working now, thanks to the documentation "Running a Phoenix master project".

First I had to delete the phoenix.new thing inside /Users/yourusername/.mix/archives
and then git clone https://github.com/phoenixframework/phoenix and cd into that directory and into the installer folder
then create the project with the --dev flag inside of there:
mix phoenix.new projectname --dev
.. follow the install steps.
mix phoenix.gen.model User users email:unique crypted_password
then works :)

@ericmj
Contributor
ericmj commented Dec 5, 2015
@nacengineer

FWIW to run from master you just need to change the source of phoenix in mix.exs

{:phoenix, "~> 1.0.4"}

becomes

{:phoenix, git: "https://github.com/phoenixframework/phoenix.git", tag: "master"}

note that you may have mix dependency errors use mix help deps or add override: true if you're feeling lucky

{:phoenix, git: "https://github.com/phoenixframework/phoenix.git", tag: "master", override: true}

then run

mix do deps.get, compile
@Immortalin

@nacengineer thanks!

@acrolink

Is it possible using mix phoenix.gen.model .. to specify a composite unique key? i.e I need a unique key based on values of two fields together. Thanks.

@josevalim
Member

@acrolink then you should rather change the generated migration. There is a certain limit of expressivity we can add to the command line instruction. However, the migration is code, and there you will have much more flexibility.

@acrolink

@josevalim I guess I can skip the migration file and define the keys on the postgres shell? Correct?

@josevalim
Member

If you define on the shell, who is going to guarantee you will remember to do that in production or that you and your co-workers will remember to the same on your machines in development? The migration is the way to go, change the file, just don't do so through the command line.

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