Sunday, January 15, 2017

Re: models foreign key

On Thu, Jan 12, 2017 at 01:40:43AM -0800, jeffreyequizuvero wrote:
>
>
> *This is about the models foreign key, I have two tables and i used foreign
> key to connect these tables however after i did migration it's not working.
> Is there any wrong with my code? *

I can see that you have a commented-out "managed = False" in the
definition of your models. Did you create and apply migrations before,
or after you commented the attribute out? If you ran your migrations
with managed = False, then it's expected that those tables are ignored
for migrations.

If that's not it, then I'm afraid you'll have to provide more details
than "it's not working" – what steps did you take exactly, what was
the output, what output did you expect, etc.

Good luck,

Michal

> *please help, Thanks. *
>
>
> class *Author*(models.Model):
> * Author_code = models.CharField(max_length=50,unique=True)*
> Author_Fname = models.CharField(max_length=30, blank=True, null=True)
> Author_Mname = models.CharField(max_length=30, blank=True, null=True)
> Author_Lname = models.CharField(max_length=30, blank=True, null=True)
>
> class Meta:
> # managed = False
> db_table = 'Author'
>
>
> class *Book*(models.Model):
>
> Book_code = models.CharField(max_length=50, blank=True,
> default=user_code_key,unique=True)
> * Author_code = models.ForeignKey(Author, to_field=Author_code',
> on_delete=models.CASCADE)*
> Book_title = models.CharField(max_length=50, blank=True, null=True)
>
> class Meta:
> # managed = False
> db_table = 'Book'
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8a12da9-8983-4375-b7ff-fa631d4522a0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20170116064111.GM1628%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment