hi,

in the case of my application here is what i done (I start from
scratch):

1. django-admin.py startproject ksk
2. django-admin.py startapp main
3. edit the settings.py file: database engine, name, user, password,
password, and then add the ksk.main in the installed_apps

INSTALLED_APPS = (
    'ksk.main',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',


)

4. cd into the main directory and edit the models.py

here is the ksk.main application models.py

from django.db import models
from django.contrib.admin.models import User

# Create your models here.
class Profile(models.Model):
    user = models.ForeignKey(User)
    department = models.CharField(maxlength=20)
    level = models.CharField(maxlength=3)

class CellUsage(models.Model):
    profile = models.ForeignKey(Profile)
    minutes = models.PositiveSmallIntegerField()

5. then i run python manage.py syncdb

the result is ... in my cellusage table there is no foreign key
created. but in the profile table there is a foreign created.

6. I delete all the tables again. I re order the items in the
INSTALLED_APPS settings. from my step no. 3 instead of putting
ksk.main in the last I put it in the first, then run manage.py syncdb

the result is no foreign key on cellusage table and in the profile
table also ...

When I say I follow the django official I was referring to the apps I
created with the tutorial. That results to no foreign key created on
the choice table.


Please help me, I am really desperate to know where did I go wrong.
Why is it a foreign key can't be created with a simple relationship.
Why is it that the order of application in the INSTALLED_APPS has
effect when performing manage.py syncdb?

iam using django .96, my python mysql driver is the latest version., i
am doing this on windows env.

Thanks Russ for helping me on this, i greatly appreciate it.

james


On Jul 21, 9:07 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/21/07, james_027 <[EMAIL PROTECTED]> wrote:
>
>
>
> > I dont know what you mean by what_I_have_done?
>
> Help me to replicate exactly the steps that you have taken to make
> this problem occur. I have your model file. If _I_ use that model
> file, and it works fine for me. Obviously you have done something
> different somewhere else. What is it? The only way to work that out is
> for you to tell me EVERYTHING you have done. For example:
>
> - I created a new project with ./django-admin.py startproject myproject
> - I created a new application with ./manage.py startapp myapp
> - I created a MySQL database using InnoDB tables
> - I modified models.py to look like ....
>
> and so on, listing EVERY change you have made.
>
> > I just follow the django tutorial. the one with poll and choice model.
> > I did every step. and that's my result.
>
> No, you didn't 'just follow the django tutorial'. If you had followed
> the Django tutorial, your models file would have contained two models
> named Poll and Choice, not a single model called Profile. I can't read
> your mind to work out which steps you changed, and how you changed
> them. Help me to retrace your steps.
>
>
>
> > However I have discover something ....
> ...
> > will produce a different result ... the first setting will have
> > foreign key on the django_admin_log table while the 2nd table dont
> > have the foreign key. I have do this multiple time, changing the
> > settings between the first and the second and the result is constant.
>
> There will be differences in the SQL that is generated, but that's
> only because of the handling of forward references.
>
> I've tried creating the tables for the two INSTALLED_APPS settings you
> describe. I'm not a MySQL expert, but as far as I can make out, I'm
> getting exactly the same tables created both ways.
>
> The only issue I can think of that could be affecting this is ticket
> #2720 [1] -
> if I remember correctly, if you're using InnoDB tables, the foreign
> key column is created, but the constraint is not. Which brings me back
> to my other question - exactly what do you mean when you say 'the 2nd
> table doesn't have the foreign key', and how did you come to this
> conclusion? Can you provide any output to show me exactly what has
> been created on the database (e.g., the result of running "describe
> django_admin_log" at an SQL prompt)
>
> [1]http://code.djangoproject.com/ticket/2720
>
> Yours,
> Russ Magee %-)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to