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

Unknown type `unique` given to generator #1326

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

Comments

Projects
None yet
7 participants
@bigbassroller

bigbassroller commented Oct 30, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Gazler

Gazler Oct 30, 2015

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Oct 30, 2015

Member

@Gazler is right. :)

Member

josevalim commented Oct 30, 2015

@Gazler is right. :)

@josevalim josevalim closed this Oct 30, 2015

@bigbassroller

This comment has been minimized.

Show comment
Hide comment
@bigbassroller

bigbassroller Oct 30, 2015

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 :)

bigbassroller commented Oct 30, 2015

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 :)

@Immortalin

This comment has been minimized.

Show comment
Hide comment

Immortalin commented Dec 5, 2015

@ericmj

This comment has been minimized.

Show comment
Hide comment
@ericmj

ericmj Dec 5, 2015

Contributor
Contributor

ericmj commented Dec 5, 2015

@nacengineer

This comment has been minimized.

Show comment
Hide comment
@nacengineer

nacengineer Dec 5, 2015

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

nacengineer commented Dec 5, 2015

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

This comment has been minimized.

Show comment
Hide comment

Immortalin commented Dec 8, 2015

@nacengineer thanks!

@acrolink

This comment has been minimized.

Show comment
Hide comment
@acrolink

acrolink Jul 18, 2016

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.

acrolink commented Jul 18, 2016

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

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Jul 18, 2016

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.

Member

josevalim commented Jul 18, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@acrolink

acrolink Jul 18, 2016

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

acrolink commented Jul 18, 2016

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

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Jul 18, 2016

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.

Member

josevalim commented Jul 18, 2016

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