Re: How can I create a new table without primary key filed?

2015-11-24 Thread Rohan Nagalkar
Hi, Though its a too old question, but just thought of answering because i 
also got the same issue
One thing you can do is first migrate(syncdb) to bdatabase and then load 
the data.


On Monday, 10 November 2008 16:29:37 UTC+5:30, XQ Kuang wrote:
>
> Hi, all. 
>
> How can I create a new table without primary key in Django modeling. ? 
>
> I'm porting a old program to Django web framework. After inspect 
> database to modules.py and then syncdb, It create the id filed with 
> primary key attribute, how can I disable this feature ?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c27e5bf7-9554-4cfb-850f-024e35d3015a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I create a new table without primary key filed?

2008-11-10 Thread AndyB

If it's one to one then the field that maps to the primary key in the
other table should be unique. Why not designate that as a primary key?

I was in a similar situation integrating a legacy Access app. I simply
added an autonumber id field. Your old app will ignore it but it keeps
Django happy.

On Nov 10, 11:45 am, "K*K" <[EMAIL PROTECTED]> wrote:
> Actually this table filed is a one to one mapper to other table's
> field. this table doesn't need primary key field.
>
> But I have to keep the database schema compatible with old system so I
> have to keep it.
>
> On Nov 10, 7:20 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On Mon, Nov 10, 2008 at 7:59 PM, K*K <[EMAIL PROTECTED]> wrote:
>
> > > Hi, all.
>
> > > How can I create a new table without primary key in Django modeling. ?
>
> > > I'm porting a old program to Django web framework. After inspect
> > > database to modules.py and then syncdb, It create the id filed with
> > > primary key attribute, how can I disable this feature ?
>
> > inspectdb isn't perfect - it's just a starting point that will
> > hopefully remove the need to do a lot of typing. It is entirely
> > expected that you will need to tweak the model provided by inspectdb.
> > If inspectdb is producing an extra 'id' field in the model it
> > suggests, just delete that field from the suggested model.
>
> > However, because of the way Django operates, you will need to nominate
> > one of the fields in your model to be the primary key. In your case,
> > I'm guessing that inspectdb can't find an obvious candidate for the
> > primary key, so it has given up and put an extra 'id' field into the
> > definition it suggests.
>
> > You can choose any field you want to be the primary key (provided it
> > actually contains unique data). It doesn't matter what that field is
> > called - it just needs to set the primary_key attribute to True. For
> > example, if one of your models has a 'name' field that could be used
> > as a primary key, you would use a definition something like:
>
> >     name = models.CharField(max_length=40, primary_key=True)
>
> > 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
-~--~~~~--~~--~--~---



Re: How can I create a new table without primary key filed?

2008-11-10 Thread K*K

OK, I got it ;-)

I will try other method to implement the application.

Thx

On Nov 10, 7:43 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-11-10 at 03:41 -0800, K*K wrote:
> > Thank you for you reply.
>
> > But I mean I want to create a table without primary key field.
>
> This isn't going to work very well with Django. There are a lot of
> places in Django that use the primary key on a table to access it. So
> tables without primary keys at all aren't supported (or possible).
>
> > I want
> > to disable django's automatic add the id key with primary key feature.
>
> > The primary key field in old table doesn't exist, and I checked it's
> > not in the models.py too.
>
> Either you specify the primary key manually or Django adds it
> automatically. There's no option to avoid one altogether.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: How can I create a new table without primary key filed?

2008-11-10 Thread K*K

Actually this table filed is a one to one mapper to other table's
field. this table doesn't need primary key field.

But I have to keep the database schema compatible with old system so I
have to keep it.


On Nov 10, 7:20 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On Mon, Nov 10, 2008 at 7:59 PM, K*K <[EMAIL PROTECTED]> wrote:
>
> > Hi, all.
>
> > How can I create a new table without primary key in Django modeling. ?
>
> > I'm porting a old program to Django web framework. After inspect
> > database to modules.py and then syncdb, It create the id filed with
> > primary key attribute, how can I disable this feature ?
>
> inspectdb isn't perfect - it's just a starting point that will
> hopefully remove the need to do a lot of typing. It is entirely
> expected that you will need to tweak the model provided by inspectdb.
> If inspectdb is producing an extra 'id' field in the model it
> suggests, just delete that field from the suggested model.
>
> However, because of the way Django operates, you will need to nominate
> one of the fields in your model to be the primary key. In your case,
> I'm guessing that inspectdb can't find an obvious candidate for the
> primary key, so it has given up and put an extra 'id' field into the
> definition it suggests.
>
> You can choose any field you want to be the primary key (provided it
> actually contains unique data). It doesn't matter what that field is
> called - it just needs to set the primary_key attribute to True. For
> example, if one of your models has a 'name' field that could be used
> as a primary key, you would use a definition something like:
>
>     name = models.CharField(max_length=40, primary_key=True)
>
> 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
-~--~~~~--~~--~--~---



Re: How can I create a new table without primary key filed?

2008-11-10 Thread Malcolm Tredinnick


On Mon, 2008-11-10 at 03:41 -0800, K*K wrote:
> Thank you for you reply.
> 
> But I mean I want to create a table without primary key field. 

This isn't going to work very well with Django. There are a lot of
places in Django that use the primary key on a table to access it. So
tables without primary keys at all aren't supported (or possible).

> I want
> to disable django's automatic add the id key with primary key feature.
> 
> The primary key field in old table doesn't exist, and I checked it's
> not in the models.py too.

Either you specify the primary key manually or Django adds it
automatically. There's no option to avoid one altogether.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: How can I create a new table without primary key filed?

2008-11-10 Thread K*K

Thank you for you reply.

But I mean I want to create a table without primary key field. I want
to disable django's automatic add the id key with primary key feature.

The primary key field in old table doesn't exist, and I checked it's
not in the models.py too.
But after syncdb django add a primary key field 'id' automatically.

For example I wrote below in the models.py:

class TestPlanPermissions(models.Model):
userid = models.IntegerField(unique=True)
plan_id = models.IntegerField()
permissions = models.IntegerField()
grant_type = models.IntegerField()

But after sync db, django add a id filed in the table automatically:

mysql> DESCRIBE test_plan_permissions;
+-+-+--+-+-++
| Field   | Type| Null | Key | Default | Extra  |
+-+-+--+-+-++
| id  | int(11) | NO   | PRI | NULL| auto_increment |
| userid  | int(11) | NO   | UNI | NULL||
| plan_id | int(11) | NO   | | NULL||
| permissions | int(11) | NO   | | NULL||
| grant_type  | int(11) | NO   | | NULL||
+-+-+--+-+-++
5 rows in set (0.00 sec)

I don't want to create neither the id field nor other primary key
field.



On Nov 10, 7:20 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On Mon, Nov 10, 2008 at 7:59 PM, K*K <[EMAIL PROTECTED]> wrote:
>
> > Hi, all.
>
> > How can I create a new table without primary key in Django modeling. ?
>
> > I'm porting a old program to Django web framework. After inspect
> > database to modules.py and then syncdb, It create the id filed with
> > primary key attribute, how can I disable this feature ?
>
> inspectdb isn't perfect - it's just a starting point that will
> hopefully remove the need to do a lot of typing. It is entirely
> expected that you will need to tweak the model provided by inspectdb.
> If inspectdb is producing an extra 'id' field in the model it
> suggests, just delete that field from the suggested model.
>
> However, because of the way Django operates, you will need to nominate
> one of the fields in your model to be the primary key. In your case,
> I'm guessing that inspectdb can't find an obvious candidate for the
> primary key, so it has given up and put an extra 'id' field into the
> definition it suggests.
>
> You can choose any field you want to be the primary key (provided it
> actually contains unique data). It doesn't matter what that field is
> called - it just needs to set the primary_key attribute to True. For
> example, if one of your models has a 'name' field that could be used
> as a primary key, you would use a definition something like:
>
>     name = models.CharField(max_length=40, primary_key=True)
>
> 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
-~--~~~~--~~--~--~---



Re: How can I create a new table without primary key filed?

2008-11-10 Thread Russell Keith-Magee

On Mon, Nov 10, 2008 at 7:59 PM, K*K <[EMAIL PROTECTED]> wrote:
>
> Hi, all.
>
> How can I create a new table without primary key in Django modeling. ?
>
> I'm porting a old program to Django web framework. After inspect
> database to modules.py and then syncdb, It create the id filed with
> primary key attribute, how can I disable this feature ?

inspectdb isn't perfect - it's just a starting point that will
hopefully remove the need to do a lot of typing. It is entirely
expected that you will need to tweak the model provided by inspectdb.
If inspectdb is producing an extra 'id' field in the model it
suggests, just delete that field from the suggested model.

However, because of the way Django operates, you will need to nominate
one of the fields in your model to be the primary key. In your case,
I'm guessing that inspectdb can't find an obvious candidate for the
primary key, so it has given up and put an extra 'id' field into the
definition it suggests.

You can choose any field you want to be the primary key (provided it
actually contains unique data). It doesn't matter what that field is
called - it just needs to set the primary_key attribute to True. For
example, if one of your models has a 'name' field that could be used
as a primary key, you would use a definition something like:

name = models.CharField(max_length=40, primary_key=True)

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
-~--~~~~--~~--~--~---