What exactly isn't working? Are you getting an error message?

I can see a few potential problems:

   - You're missing a quotation mark around Author_code in the *to_field* 
   parameter;
   - The fields on both models have the same name, this might cause 
   problems.



On Thursday, January 12, 2017 at 10:40:43 AM UTC+1, 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? *
>
> *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+unsubscr...@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/fb32e401-f1a6-4180-a49a-12c86b09bed5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to