Re: Django dynamic multiple databases

2023-08-12 Thread ivan harold
you can check this one 
out https://docs.djangoproject.com/en/4.2/topics/db/multi-db/

On Saturday, August 12, 2023 at 9:44:08 AM UTC-5 pankaj palmate wrote:

> I want to creating  saas based application containing one super admin and 
> rest will be customers where each customer will have their own database 
> .want multiple database with dynamic credentials based on request.I want 
> the database to be identified from the subdomain provided.Is this possible 
> using django ? If yes how ? If not what's the option? 
> I did read about the django tenants but it is schema based but I want 
> multiple database approach while creating tenants.(database must be 
> identified from subdomains ) 
>
> Thanks and regards,
> Pankaj palmate 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/25e13400-be07-48da-85f6-a3b9f2d12b78n%40googlegroups.com.


Django dynamic multiple databases

2023-08-12 Thread pankaj palmate
I want to creating  saas based application containing one super admin and
rest will be customers where each customer will have their own database
.want multiple database with dynamic credentials based on request.I want
the database to be identified from the subdomain provided.Is this possible
using django ? If yes how ? If not what's the option?
I did read about the django tenants but it is schema based but I want
multiple database approach while creating tenants.(database must be
identified from subdomains )

Thanks and regards,
Pankaj palmate

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPyMU1JJXUXXDLBSy4V-f-YYex9ZuaPP1CAL%3DPZSFkvhsc5K4Q%40mail.gmail.com.


Re: Running migrations with multiple databases

2023-07-11 Thread shahee...@gmail.com
Thanks: just what I needed to know!

On Tuesday, 11 July 2023 at 02:48:48 UTC+1 David Nugent wrote:

Migrations are executed according to how your db routers is setup.

See setting DATABASE_ROUTERS.

Note that normally you would be replicating secondaries, so migrations are 
normally not applied on all bu the primary, so this is the default.

Regards,
David

On Mon, Jul 10, 2023 at 10:26 PM Shaheed Haque  wrote:

Hi,

I'm on Django 4.2 atop Postgres. In my project settings.py, I have a 
main/default database connection, and a second set up like this:

==
DATABASES = {
'default': {
...
'NAME': 'foo', # Postgres DATABASE NAME
...
},
'archive_restore': {
...
'NAME': 'archive_restore',   # Postgres DATABASE NAME
...
},
# Other entries for specialised purposes such as custom Postgres 
Foreign Data Wrappers.
===

As you can see, the Postgres database names are "foo" and "archive_restore" 
respectively. For all normal Django purposes, we want to use "default", aka 
"foo". The "archive_restore" connection/database is used in conjunction 
with a bunch of psql commands to create a subset of the main Django ORM 
data. Once populated via pg_restore, I need to run the DJango migrations on 
them for eventual use under Django. I had assumed that a command like this:

./manage.py migrate --database archive_restore

would modify archive_restore/archive_restore. However, what seems to happen 
is that the migrations are:

   - Actually run in default/foo (the migrations include code generated by 
   makemigrations and custom RunPython stuff).
   - But recorded in the django_migrations table in 
   archive_restore/archive_restore.

whereas I was expecting that they would be both run and recorded in the 
latter. Have I overlooked some setting/restriction, or is this a bug?

Thanks, Shaheed




-- 
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...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2je%2B%3D67tZBeGBMUO8Dmqmq9SaCRuopLxqrECuXb1C8YriQ%40mail.gmail.com
 

.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e5abb96-10bc-43e9-bd33-6328e62f2c46n%40googlegroups.com.


Re: Running migrations with multiple databases

2023-07-10 Thread David Nugent
Migrations are executed according to how your db routers is setup.

See setting DATABASE_ROUTERS.

Note that normally you would be replicating secondaries, so migrations are
normally not applied on all bu the primary, so this is the default.

Regards,
David

On Mon, Jul 10, 2023 at 10:26 PM Shaheed Haque 
wrote:

> Hi,
>
> I'm on Django 4.2 atop Postgres. In my project settings.py, I have a
> main/default database connection, and a second set up like this:
>
> ==
> DATABASES = {
> 'default': {
> ...
> 'NAME': 'foo', # Postgres DATABASE NAME
> ...
> },
> 'archive_restore': {
> ...
> 'NAME': 'archive_restore',   # Postgres DATABASE NAME
> ...
> },
> # Other entries for specialised purposes such as custom Postgres
> Foreign Data Wrappers.
> ===
>
> As you can see, the Postgres database names are "foo" and
> "archive_restore" respectively. For all normal Django purposes, we want to
> use "default", aka "foo". The "archive_restore" connection/database is used
> in conjunction with a bunch of psql commands to create a subset of the main
> Django ORM data. Once populated via pg_restore, I need to run the DJango
> migrations on them for eventual use under Django. I had assumed that a
> command like this:
>
> ./manage.py migrate --database archive_restore
>
> would modify archive_restore/archive_restore. However, what seems to
> happen is that the migrations are:
>
>- Actually run in default/foo (the migrations include code generated
>by makemigrations and custom RunPython stuff).
>- But recorded in the django_migrations table in
>archive_restore/archive_restore.
>
> whereas I was expecting that they would be both run and recorded in the
> latter. Have I overlooked some setting/restriction, or is this a bug?
>
> Thanks, Shaheed
>
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHAc2je%2B%3D67tZBeGBMUO8Dmqmq9SaCRuopLxqrECuXb1C8YriQ%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgXQj3yTmiqvKn3hVoBD7PT4aF58aXtN9euUs_AgEiLTvw%40mail.gmail.com.


Running migrations with multiple databases

2023-07-10 Thread Shaheed Haque
Hi,

I'm on Django 4.2 atop Postgres. In my project settings.py, I have a
main/default database connection, and a second set up like this:

==
DATABASES = {
'default': {
...
'NAME': 'foo', # Postgres DATABASE NAME
...
},
'archive_restore': {
...
'NAME': 'archive_restore',   # Postgres DATABASE NAME
...
},
# Other entries for specialised purposes such as custom Postgres
Foreign Data Wrappers.
===

As you can see, the Postgres database names are "foo" and "archive_restore"
respectively. For all normal Django purposes, we want to use "default", aka
"foo". The "archive_restore" connection/database is used in conjunction
with a bunch of psql commands to create a subset of the main Django ORM
data. Once populated via pg_restore, I need to run the DJango migrations on
them for eventual use under Django. I had assumed that a command like this:

./manage.py migrate --database archive_restore

would modify archive_restore/archive_restore. However, what seems to happen
is that the migrations are:

   - Actually run in default/foo (the migrations include code generated by
   makemigrations and custom RunPython stuff).
   - But recorded in the django_migrations table in
   archive_restore/archive_restore.

whereas I was expecting that they would be both run and recorded in the
latter. Have I overlooked some setting/restriction, or is this a bug?

Thanks, Shaheed

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2je%2B%3D67tZBeGBMUO8Dmqmq9SaCRuopLxqrECuXb1C8YriQ%40mail.gmail.com.


Re: Using Multiple databases

2022-04-15 Thread Ryan Nowakowski
On Wed, Apr 06, 2022 at 08:59:09AM -0700, Vasanth Mohan wrote:
> I'm building a PoC for a multi-tenant app where I'm trying to use the same 
> schema across multiple databases with Django instance. I've got a couple of 
> questions and I'd be happy to have some input
> 
> 1. Is there a way to define the *using()* function to use with Models via a 
> lib/middleware?
> 2. Is there a way to create admin users so that they have access to 
> specific databases? 

You probably want to create a custom database router[1].

[1] 
https://docs.djangoproject.com/en/4.0/topics/db/multi-db/#automatic-database-routing

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20220415180748.GC15520%40fattuba.com.


Using Multiple databases

2022-04-06 Thread Vasanth Mohan
Hello,

I'm building a PoC for a multi-tenant app where I'm trying to use the same 
schema across multiple databases with Django instance. I've got a couple of 
questions and I'd be happy to have some input

1. Is there a way to define the *using()* function to use with Models via a 
lib/middleware?
2. Is there a way to create admin users so that they have access to 
specific databases? 

Regards,
Vasanth M

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3b441eb-3855-4dc1-b9d7-ee7211add752n%40googlegroups.com.


migrate exception if multiple databases migrated in a specific order

2022-02-02 Thread Robert Leach
I just added a second database to our project and was questioning my sanity 
when I kept getting the exception below in the remote github action tests 
only (not locally).  I eventually noticed that I was doing the migrations 
in the reverse order locally.  Once I noticed that, I was able to both 
reproduce the error locally and avoid the error in the github action.

There are the commands whose order matters:

Works:

python manage.py migrate
python manage.py migrate --database=validation

Results int eh exception:

python manage.py migrate --database=validation
python manage.py migrate

I do not understand why the order matters, but my guess is that there is 
some code that runs in the migrate command that ignores the --database 
setting when creating relations.  Is this true?  Or is there a reasonable 
reason why it MUST be done in the order `default` then `non-default`?

Here is what I have in settings.py:

```
DATABASES = {
   "default": {
   "ENGINE": "django.db.backends.postgresql",
   "NAME": env("DATABASE_NAME"),
   "USER": env("DATABASE_USER"),
   "PASSWORD": env("DATABASE_PASSWORD"),
   "HOST": env("DATABASE_HOST"),
   "PORT": env("DATABASE_PORT"),
   }
}

VALIDATION_ENABLED = False
# If the validation database is configured in the .env file...
if env("VALIDATION_DATABASE_NAME"):
   try:
   DATABASES["validation"] = {
   "ENGINE": "django.db.backends.postgresql",
   "NAME": env("VALIDATION_DATABASE_NAME"),
   "USER": env("VALIDATION_DATABASE_USER"),
   "PASSWORD": env("VALIDATION_DATABASE_PASSWORD"),
   "HOST": env("VALIDATION_DATABASE_HOST"),
   "PORT": env("VALIDATION_DATABASE_PORT"),
   }
   VALIDATION_ENABLED = True
   except Exception as e:
   print(
   f"Could not configure access to the 
{env('VALIDATION_DATABASE_NAME')} database: {e}"
   )
```

The exception I get is below.  So have I found a bug or is there something 
for me to learn here?

Thanks,
Rob


The exception:

Running migrations:
 Applying DataRepo.0001_initial... OK
 Applying DataRepo.0002_RemoveDefaultProtocolCategory... OK
 Applying DataRepo.0003_remove_animal_state... OK
 Applying DataRepo.0004_StandardizeMsrun... OK
 Applying DataRepo.0005_auto_20210721_1444... OK
 Applying DataRepo.0006_auto_20210909_1607... OK
 Applying DataRepo.0007_tissue_description... OK
 Applying DataRepo.0008_null_original_peakdata... OK
 Applying DataRepo.0009_compound_synonym... OK
Traceback (most recent call last):
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/db/backends/utils.py",
 
line 84, in _execute
   return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "DataRepo_compound" does not exist
LINE 1: ...nd"."formula", "DataRepo_compound"."hmdb_id" FROM "DataRepo_...
^
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 File "manage.py", line 22, in 
   main()
 File "manage.py", line 18, in main
   execute_from_command_line(sys.argv)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/__init__.py",
 
line 419, in execute_from_command_line
   utility.execute()
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/__init__.py",
 
line 413, in execute
   self.fetch_command(subcommand).run_from_argv(self.argv)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/base.py",
 
line 354, in run_from_argv
   self.execute(*args, **cmd_options)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/base.py",
 
line 398, in execute
   output = self.handle(*args, **options)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/base.py",
 
line 89, in wrapped
   res = handle_func(*args, **kwargs)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/core/management/commands/migrate.py",
 
line 244, in handle
   post_migrate_state = executor.migrate(
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/db/migrations/executor.py",
 
line 117, in migrate
   state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
fake_initial=fake_initial)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/db/migrations/executor.py",
 
line 147, in _migrate_all_forwards
   state = self.apply_migration(state, migration, fake=fake, 
fake_initial=fake_initial)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/db/migrations/executor.py",
 
line 227, in apply_migration
   state = migration.apply(state, schema_editor)
 File 
"/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/django/db/migrations/migration.py",
 
line 126, in apply
   

call the model of the secondary database in djnago using Multiple Databases

2020-06-30 Thread Pradyum Gupta
https://stackoverflow.com/q/62658396/7999665

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5a9e3323-bc2d-47af-b971-b54df2524057n%40googlegroups.com.


Re: Can we create a Rest Api in Django which can able to communicate with multiple databases(Relational, Non relational) dynamically. If yes please recommend me a way to do that

2019-06-23 Thread Andrew C.
There really isn’t any point in doing that. 1) You should just use one of
the two. Django officially supports Postgres. 2) You’d want to keep your
users all jumbled in one database. If you have a foreign key to the
username field, and the db can’t find a specific user because it’s in the
other db, then what do you do then?

You wouldn’t need a REST api to do whatever your case is. Django supports
using multiple database; just check their doc with a google search. It’s
just a lot more business logic, and in my opinion, a lot more work and
inefficiency.

On Fri, Jun 21, 2019 at 7:25 AM anilkumar sangu 
wrote:

> Hello,
>
> I am working on Django
>
> I have a scenario like
> I want to connect multiple databases. based on user selection.  if user
> selects MySql from front end my Api could able to connect MySql. if user
> select postgreSql my api could able to connect to postgreSql based on user
> selection dynamically. how to achieve this in Django Rest Api
>
> Thanks in advance
>
> --
> 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/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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+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/CAJVmkN%3DW_Mk7L_zRMLZ8xwF5h4%2BPsDQE0jfamPBJS%2Br9mA%3D%2BNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can we create a Rest Api in Django which can able to communicate with multiple databases(Relational, Non relational) dynamically. If yes please recommend me a way to do that

2019-06-21 Thread Chetan Ganji
If it is one time selection like storing in a user level settings, you can
store the database to use in user model
i.e. you have to customize default Usermodel in django and add one extra
field to store the db type of the current user.

Then access the right db

Author.objects.using(request.user.database).all()

OR

Author.objects.using('mysql').all()

Author.objects.using('postgresql').all()

You might have to use the database routers also. It depends on your
detailed requirements.


Official docs -
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/

Cheers!


Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Jun 21, 2019 at 4:55 PM anilkumar sangu 
wrote:

> Hello,
>
> I am working on Django
>
> I have a scenario like
> I want to connect multiple databases. based on user selection.  if user
> selects MySql from front end my Api could able to connect MySql. if user
> select postgreSql my api could able to connect to postgreSql based on user
> selection dynamically. how to achieve this in Django Rest Api
>
> Thanks in advance
>
> --
> 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/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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+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/CAMKMUjuH_j_OGDpLQfQQZ8EqChRTXXvutNb%3DK%2BJEv76QJeQmFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can we create a Rest Api in Django which can able to communicate with multiple databases(Relational, Non relational) dynamically. If yes please recommend me a way to do that

2019-06-21 Thread anilkumar sangu
Hello,

I am working on Django

I have a scenario like 
I want to connect multiple databases. based on user selection.  if user 
selects MySql from front end my Api could able to connect MySql. if user 
select postgreSql my api could able to connect to postgreSql based on user 
selection dynamically. how to achieve this in Django Rest Api

Thanks in advance 

-- 
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/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple databases in django with admin

2019-02-14 Thread Ramesh Mahajan
I am working on a project for multiple tenants. So i want to multiple 
databases. But i will be using django built-in auth app. I want to know 
what changes I should do in admin panel so that whenever admin is creating 
user it goes and sits in the respective databases. Thank in advance.

-- 
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/e478de14-9b6b-4c01-bfa7-5db1aada1560%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Single Django App using Multiple Databases

2018-10-02 Thread heriberto ochoa
https://django-tenant-schemas.readthedocs.io/en/latest/

El martes, 2 de octubre de 2018, 6:53:16 (UTC-6), Glen D souza escribió:
>
> Hi,
>
> I am working on a project where i am using a single django app which is 
> backed by different databases.
>
> Let me explain the use case clearly,
>
> I have a app say app1, and app1 data is located in two different databases 
> say db1 and db2
> data present in the db1 and db2 are different, lets say db1 holds the data 
> for state 'CA' and db2 holds the data for state 'TX'.
>
> I am using django admin interface for populating/viewing data through app1
>
> In order to do db routing i am using sub domains, i.e if user wants to 
> view the data from ca he has to do ca.localhost:8000 and if he wants to 
> view the data for tx he has to do tx.localhost:8000
>
> So from the url i am capturing the sub-domain and using it for db routing.
>
> Till this part my app works fine it displays the data correctly
>
> Now my problem is since i am using django admin to display data, when db1 
> has a model x which is not present in db2 or db1 y model is different from 
> y model present in db2 how to dispaly such model through django admin?
>
> To elaborate lets say db1 has models x y and db2 has models z y1 (y and y1 
> are slighlty different)
>
> i have corresponding django models for db1 and db2, lets say dj_model for 
> db1 is ca_x, ca_y and for db2 is tx_z and tx_y1 
>
> when user goes to ca.localhost:8000 i want my admin page to display only 
> the ca models i.e ca_x, ca_y
> So i want to dynamically register the models in admin.py i.e
> when user goes to ca.localhost:8000 i want my admin.py to look something 
> like this admin.site.register(ca_x, ca_y)
> when user goes to tx.localhost:8000 i want my admin.py to look something 
> like this
> admin.site.register(tx_z, tx_y1)
>
> Any idea how to implement this? or any other alternate approaches, right 
> now i can restrict the user based on permission but i want to know are 
> there any other methods?
>
>
>

-- 
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/621cbab6-55fa-4d56-bcff-b980ae2a5cb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Single Django App using Multiple Databases

2018-10-02 Thread Glen D souza
Hi,

I am working on a project where i am using a single django app which is
backed by different databases.

Let me explain the use case clearly,

I have a app say app1, and app1 data is located in two different databases
say db1 and db2
data present in the db1 and db2 are different, lets say db1 holds the data
for state 'CA' and db2 holds the data for state 'TX'.

I am using django admin interface for populating/viewing data through app1

In order to do db routing i am using sub domains, i.e if user wants to view
the data from ca he has to do ca.localhost:8000 and if he wants to view the
data for tx he has to do tx.localhost:8000

So from the url i am capturing the sub-domain and using it for db routing.

Till this part my app works fine it displays the data correctly

Now my problem is since i am using django admin to display data, when db1
has a model x which is not present in db2 or db1 y model is different from
y model present in db2 how to dispaly such model through django admin?

To elaborate lets say db1 has models x y and db2 has models z y1 (y and y1
are slighlty different)

i have corresponding django models for db1 and db2, lets say dj_model for
db1 is ca_x, ca_y and for db2 is tx_z and tx_y1

when user goes to ca.localhost:8000 i want my admin page to display only
the ca models i.e ca_x, ca_y
So i want to dynamically register the models in admin.py i.e
when user goes to ca.localhost:8000 i want my admin.py to look something
like this admin.site.register(ca_x, ca_y)
when user goes to tx.localhost:8000 i want my admin.py to look something
like this
admin.site.register(tx_z, tx_y1)

Any idea how to implement this? or any other alternate approaches, right
now i can restrict the user based on permission but i want to know are
there any other methods?

-- 
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/CAHfehoV%2BWhv8fTPYYPwKhHGF9_5ycHcr_-JS71p6E7sSfTVZzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Regarding Multiple Databases

2018-06-19 Thread RASHMIT PANKHANIA
hi i m here first time, my doubt is regarding using multiple(two) databases 
and i want to create particular table in only one database but after 
migrating it happens on both.you can follow the code on 
https://dpaste.de/arP9

-- 
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/87e24941-d3f3-4bf5-bba6-f090071198f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Regarding Multiple Databases

2018-06-19 Thread RASHMIT PANKHANIA
Hello:
I am Rashmit Pankhania and my doubt is regarding using multiple(two) 
databases and i want to create particular table in only one database but 
after migrating it happens on both.Also after migrating it show only 
django-migration table in second database.you can follow the code on 
https://dpaste.de/arP9.Any help from your side will really be appreciated.
Thanking you for your anticipation.

Rashmit Pankhania
rashmitpankha...@gmail.com
(+91)9173670547

-- 
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/a2da93f1-064c-4b21-8088-2f1de10e57a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


database names in queries on multiple databases

2017-07-10 Thread Florian Wegscheider
TLTR: Django does not include database names in SQL queries, can I somehow 
force it to do this, or is there a workaround?

The long version:

I have two unmanaged legacy MySQL databases (Note: I have no influence on 
the DB layout) for which I'm creating a readonly API using DRF on Django 
1.11 and python 3.6 

I'm working around the referential integrity limitation of MyISAM DBs by 
using the SpanningForeignKey field suggested here: 
https://stackoverflow.com/a/32078727/7933618

I'm trying to connect a table from DB1 to a table from DB2 via a ManyToMany 
through table on DB1. That's the query Django is creating:
  
SELECT "table_b"."id" FROM "table_b" INNER JOIN "throughtable" ON ("table_b"
."id" = "throughtable"."b_id") WHERE "throughtable"."b_id" = 12345

Which of course gives me an Error "Table 'DB2.throughtable' doesn't exist" 
because throughtable is on DB1 and I have no idea how to force Django to 
prefix the tables with the DB name. The query should be:
   
SELECT table_b.id FROM DB2.table_b INNER JOIN DB1.throughtable ON (table_b.id 
= throughtable.b_id) WHERE throughtable.b_id = 12345

Models for app1 `db1_app/models.py`:

class TableA(models.Model):
id = models.AutoField(primary_key=True)
# some other fields
relations = models.ManyToManyField(TableB, through='Throughtable')


class Throughtable(models.Model):
id = models.AutoField(primary_key=True)
a_id = models.ForeignKey(TableA, to_field='id')
b_id = SpanningForeignKey(TableB, db_constraint=False, to_field='id'
)

Models for app2 `db2_app/models.py`:

class TableB(models.Model):
id = models.AutoField(primary_key=True)
# some other fields

Database router:

def db_for_read(self, model, **hints):
if model._meta.app_label == 'db1_app':
return 'DB1'

if model._meta.app_label == 'db2_app':
return 'DB2'

return None

Can I force Django to include the database name in the query? Or is there 
any workaround for this?

I also posted this question on StackOverflow - to no avail, so I'll try 
here.
https://stackoverflow.com/questions/45018277/django-manytomany-through-with-multiple-databases

-- 
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/0f4e3da3-7fbe-4abf-a3a4-77bb0415e6a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple Databases --- Migrations

2017-02-27 Thread Luvpreet Singh


I am using 2 postgres databases in my django app.



 'newpostgre': {
   'ENGINE': 'django.db.backends.postgresql_psycopg2',
   'NAME': 'new_postgre2',
   'USER': 'tester',
   'PASSWORD': 'password',
   'HOST': 'localhost',
   'PORT': '',
   },
   

 'newpostgre2': {
  'ENGINE': 'django.db.backends.postgresql_psycopg2',
  'NAME': 'new_postgre3',
  'USER': 'tester',
  'PASSWORD': 'password',
  'HOST': 'localhost',
  'PORT': '',
 },


I have a very simple model

 

 class Check1(models.Model):
  title = models.CharField(max_length=100)


I had run

 

python manage.py migrate --database=newpostgre
python manage.py migrate --database=newpostgre2


when I open my new_postgre2(for newpostgre) database in postgre, I can see 
my Check1 table there.


But in my new_postgre3(for newpostgre2) database in postgre, no Check1 
table is there, only those initial migrations are there.


Why I can't see my table in new_postgre3 when migrations have been 
successfully made? Or is there any rule that model can be migrated to only 
1 database ?

-- 
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/8634-5cba-45a5-b4ef-aa446a0328c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Databases

2017-02-27 Thread ludovic coues
Have you checked your settings for typo ?

2017-02-27 10:02 GMT+01:00 Luvpreet Singh :
> But dylan, I have written that
>
> Check1.objects.using('default').all()
>
> gives me error.
>
> On Mon, Feb 27, 2017 at 1:08 PM, Dylan Reinhold  wrote:
>>
>> It is going to use the database named default.
>> Checkout the doc on using mutiple DBs
>> https://docs.djangoproject.com/en/1.10/topics/db/multi-db/
>>
>> Dylan
>>
>>
>> On Sun, Feb 26, 2017 at 11:17 PM, Luvpreet Singh 
>> wrote:
>>>
>>> Hi everyone,
>>>
>>> I am using 2 databases in my django app. One is default sqlite and second
>>> is postgre.
>>>
>>> Now, I make a simple model named Check1 in my app, having only title
>>> attribute.
>>>
>>> class Check1(models.Model):
>>>   title = models.CharField(max_length=100)
>>>
>>> Now, in my shell,
>>>
>>> >> from check.models import Check1
>>> >> a = Check1(title="first")
>>> >> a.save()
>>> >> Check1.objects.all()   --> this gives the queryset returning 'first'
>>>
>>>
>>> My question is, in which database is it saved, means in my default db or
>>> my postgre db ? or in both ?
>>>
>>> >> Check1.objects.using('default').all()--> it gives me error
>>> >> Check1.objects.using('newpostgre').all()  --> it gives me correct
>>> >> queryset.
>>>
>>> How does I know or set that in which db it will be saved ?
>>>
>>> --
>>> 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/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/5sxIoy0mDcE/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAHtg44BO8P5N-AfYvCjPnBn2p_GxRK9HQ_SRiUw8PWgWfKdtfA%40mail.gmail.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+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/CAL%2BrqijFBegKbKGmSAZgFEFpJWn75hVoCOYxPJi%3DLHFBrNs_FQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTbCb1wTMTYwP4dKu-Ao1Xec5o%2Bk9DAMxsyP2ZRtuEbPZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Databases

2017-02-27 Thread Luvpreet Singh
But dylan, I have written that

Check1.objects.using('default').all()

gives me error.

On Mon, Feb 27, 2017 at 1:08 PM, Dylan Reinhold  wrote:

> It is going to use the database named default.
> Checkout the doc on using mutiple DBs
> https://docs.djangoproject.com/en/1.10/topics/db/multi-db/
>
> Dylan
>
>
> On Sun, Feb 26, 2017 at 11:17 PM, Luvpreet Singh 
> wrote:
>
>> Hi everyone,
>>
>> I am using 2 databases in my django app. One is default sqlite and second
>> is postgre.
>>
>> Now, I make a simple model named Check1 in my app, having only title
>> attribute.
>>
>> class Check1(models.Model):
>>   title = models.CharField(max_length=100)
>>
>> Now, in my shell,
>>
>> >> from check.models import Check1
>> >> a = Check1(title="first")
>> >> a.save()
>> >> Check1.objects.all()   --> this gives the queryset returning 'first'
>>
>>
>> My question is, in which database is it saved, means in my default db or
>> my postgre db ? or in both ?
>>
>> >> Check1.objects.using('default').all()--> it gives me error
>> >> Check1.objects.using('newpostgre').all()  --> it gives me correct
>> queryset.
>>
>> How does I know or set that in which db it will be saved ?
>>
>> --
>> 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/ms
>> gid/django-users/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/5sxIoy0mDcE/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAHtg44BO8P5N-AfYvCjPnBn2p_GxRK9HQ_SRiUw8PWgWfKdtfA%
> 40mail.gmail.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+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/CAL%2BrqijFBegKbKGmSAZgFEFpJWn75hVoCOYxPJi%3DLHFBrNs_FQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Databases

2017-02-26 Thread Dylan Reinhold
It is going to use the database named default.
Checkout the doc on using mutiple DBs
https://docs.djangoproject.com/en/1.10/topics/db/multi-db/

Dylan


On Sun, Feb 26, 2017 at 11:17 PM, Luvpreet Singh 
wrote:

> Hi everyone,
>
> I am using 2 databases in my django app. One is default sqlite and second
> is postgre.
>
> Now, I make a simple model named Check1 in my app, having only title
> attribute.
>
> class Check1(models.Model):
>   title = models.CharField(max_length=100)
>
> Now, in my shell,
>
> >> from check.models import Check1
> >> a = Check1(title="first")
> >> a.save()
> >> Check1.objects.all()   --> this gives the queryset returning 'first'
>
>
> My question is, in which database is it saved, means in my default db or
> my postgre db ? or in both ?
>
> >> Check1.objects.using('default').all()--> it gives me error
> >> Check1.objects.using('newpostgre').all()  --> it gives me correct
> queryset.
>
> How does I know or set that in which db it will be saved ?
>
> --
> 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/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%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+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/CAHtg44BO8P5N-AfYvCjPnBn2p_GxRK9HQ_SRiUw8PWgWfKdtfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Multiple Databases

2017-02-26 Thread Luvpreet Singh
Hi everyone,

I am using 2 databases in my django app. One is default sqlite and second 
is postgre.

Now, I make a simple model named Check1 in my app, having only title 
attribute.

class Check1(models.Model):
  title = models.CharField(max_length=100)

Now, in my shell,

>> from check.models import Check1
>> a = Check1(title="first")
>> a.save()
>> Check1.objects.all()   --> this gives the queryset returning 'first'


My question is, in which database is it saved, means in my default db or my 
postgre db ? or in both ?

>> Check1.objects.using('default').all()--> it gives me error
>> Check1.objects.using('newpostgre').all()  --> it gives me correct 
queryset.

How does I know or set that in which db it will be saved ?

-- 
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/3c65b2a4-d409-44a6-8ea9-73aa15989eb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: multiple databases - two questions

2017-01-03 Thread Fred Stluka

  
  
Mike,

Yeah.  Makes sense.  Good thought about the UUIDs!  My success 
was due partly to the fact that I could afford to move entire
tables,
not just selected rows, and could move all related tables as well.

Trying to move just some of a related set of data from one DB to
another with each DB generating its own set of auto-incremented 
PKs would have been a problem.

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 1/2/17 11:04 PM, Mike Dewhirst
  wrote:

On 3/01/2017 12:32 PM, Fred Stluka wrote:
  
  Mike,


Maybe you don't need a custom DB manager.  Perhaps a simple

DB router would suffice?  It's a Django way to specify which DB

to use based on which model is being used, whether it is being

read/written, etc.

  
  
  That's the approach I took. The essence of the problem: it ain't
  simple. There are many and varied relationships and any transfer
  of *related sets* of data to another database means transferring
  existing PKs which tie the sets together. Maybe if it was a
  foreseen design criterion we would have used UUIDs instead of
  incrementing integer ids.
  
  
  The DB router is designed for naturally segmented schemas being on
  different databases. My attempt was against the grain.
  
  
  Cheers
  
  
  Mike
  
  
  

See:

-
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing

--Fred



Fred Stluka -- mailto:f...@bristle.com --
http://bristle.com/~fred/

Bristle Software, Inc -- http://bristle.com -- Glad to be of
service!

Open Source: Without walls and fences, we need no Windows or
Gates.




On 11/4/16 12:37 AM, Mike Dewhirst wrote:

(this one might be easier to read)
  
  
  I am planning some utility helper code to push selected
  records and their children from our staging database into the
  production database. The current database would be 'default'
  and I could add a second one called 'production' then read
  from 'default' and write to 'production'. (I need to check we
  are on the staging server).
  
  
  The docs say ...
  
  
https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-managers-with-multiple-databases
  
  
  ... but I don't quite understand. There are no custom managers
  involved; only the out-of-the-box MyModel.objects.
  
  
  Q1. Should I be using db_manager()?
  
  
  The plan is to write some utility code like this ...
  
  
  from substance.models import Substance
  
  
  def
  
  write_substance_to_production(subst):
  
  
      prd_subst, create =
  
  Substance.objects.using('production').get_or_create(
  
  
      name=subst.name,
  
  
      )
  
  
      if create:
  
  
      pass
  
  
      # copy all subst attributes except id to prd_subst
  
  
  
  Q2. Is this a reasonable approach?
  
  
  Thanks for any hints
  
  
  Mike
  
  


-- 
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
<mailto:django-users+unsubscr...@googlegroups.com>.

To post to this group, send email to
django-users@googlegroups.com
<mailto: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/ee0a7b26-3330-60e2-2ad1-9ef2baa6ba40%40bristle.com
.

For more options, visit https://groups.google.com/d/optout.

  
  


 

Re: multiple databases - two questions

2017-01-02 Thread Mike Dewhirst

On 3/01/2017 12:32 PM, Fred Stluka wrote:

Mike,

Maybe you don't need a custom DB manager.  Perhaps a simple
DB router would suffice?  It's a Django way to specify which DB
to use based on which model is being used, whether it is being
read/written, etc.


That's the approach I took. The essence of the problem: it ain't simple. 
There are many and varied relationships and any transfer of *related 
sets* of data to another database means transferring existing PKs which 
tie the sets together. Maybe if it was a foreseen design criterion we 
would have used UUIDs instead of incrementing integer ids.


The DB router is designed for naturally segmented schemas being on 
different databases. My attempt was against the grain.


Cheers

Mike



See:
- 
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing


--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


On 11/4/16 12:37 AM, Mike Dewhirst wrote:

(this one might be easier to read)

I am planning some utility helper code to push selected records and 
their children from our staging database into the production 
database. The current database would be 'default' and I could add a 
second one called 'production' then read from 'default' and write to 
'production'. (I need to check we are on the staging server).


The docs say ...

https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-managers-with-multiple-databases 



... but I don't quite understand. There are no custom managers 
involved; only the out-of-the-box MyModel.objects.


Q1. Should I be using db_manager()?

The plan is to write some utility code like this ...

from substance.models import Substance

def
write_substance_to_production(subst):

prd_subst, create =
Substance.objects.using('production').get_or_create(

name=subst.name,

)

if create:

pass

# copy all subst attributes except id to prd_subst


Q2. Is this a reasonable approach?

Thanks for any hints

Mike



--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/ee0a7b26-3330-60e2-2ad1-9ef2baa6ba40%40bristle.com 
<https://groups.google.com/d/msgid/django-users/ee0a7b26-3330-60e2-2ad1-9ef2baa6ba40%40bristle.com?utm_medium=email_source=footer>.

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+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/6b9a74ec-4632-2e92-9b03-1e358976765f%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: multiple databases - two questions

2017-01-02 Thread Fred Stluka

  
  
Mike,

Maybe you don't need a custom DB manager.  Perhaps a simple
DB router would suffice?  It's a Django way to specify which DB 
to use based on which model is being used, whether it is being 
read/written, etc.

See:
-
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 11/4/16 12:37 AM, Mike Dewhirst
  wrote:

(this one might be easier to read)
  
  
  I am planning some utility helper code to push selected records
  and their children from our staging database into the production
  database. The current database would be 'default' and I could add
  a second one called 'production' then read from 'default' and
  write to 'production'. (I need to check we are on the staging
  server).
  
  
  The docs say ...
  
  
https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-managers-with-multiple-databases
  
  
  ... but I don't quite understand. There are no custom managers
  involved; only the out-of-the-box MyModel.objects.
  
  
  Q1. Should I be using db_manager()?
  
  
  The plan is to write some utility code like this ...
  
  
  from substance.models import Substance
  
  
  def
  
  write_substance_to_production(subst):
  
  
      prd_subst, create =
  
  Substance.objects.using('production').get_or_create(
  
  
      name=subst.name,
  
  
      )
  
  
      if create:
  
  
      pass
  
  
      # copy all subst attributes except id to prd_subst
  
  
  
  Q2. Is this a reasonable approach?
  
  
  Thanks for any hints
  
  
  Mike
  
  


  




-- 
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/ee0a7b26-3330-60e2-2ad1-9ef2baa6ba40%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations and multiple databases

2016-11-25 Thread odd hogstad
Isn't that kind of stupid?

fredag 25. november 2016 06.00.49 UTC+1 skrev pradam.programming følgende:
>
> Yes do the same.
>
> On Thu, Nov 24, 2016 at 11:16 PM, odd hogstad  > wrote:
>
>> db1 holds the auth stuff already. Do I need to also have it in db2 for 
>> the migrations to work?
>>
>> torsdag 24. november 2016 12.22.14 UTC+1 skrev pradam.programming 
>> følgende:
>>>
>>> hi Hogstad,
>>> Before doing app migrate please python manage.py migrate auth ==>I hope 
>>> this will solve the issue
>>>
>>> On Thu, Nov 24, 2016 at 3:54 PM, odd hogstad  
>>> wrote:
>>>
 I have two databases in my project, db1, which changes quite 
 frequently, and db2, which seldom changes. The app was original written in 
 django 1.3, but we've upgraded since then, and now uses 1.8. Now I need to 
 make a change on db2 for the first time since the upgrade from 1.3. I make 
 my changes in the model, but when I do python manage.py migrate 
 model_of_db2 db2, the changes seems to be applyed, but I get an error: 


 "Error creating new content types. Please make sure contenttypes "

 RuntimeError: Error creating new content types. Please make sure 
 contenttypes is migrated before trying to migrate apps individually.


 I tried adding a router, but same issue. What am I doing wrong? Do I 
 need contenttypes also in db2?


 Thanks!


 -- 
 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...@googlegroups.com.
 To post to this group, send email to django...@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/844ea033-380b-4103-86cc-311aec9f5abd%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...@googlegroups.com .
>> To post to this group, send email to django...@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/4dc7af3b-61d9-4128-b44a-ffbb5954214f%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+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/6b368f47-4cde-4963-b7e6-952e1ac95929%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations and multiple databases

2016-11-24 Thread pradam programming
Yes do the same.

On Thu, Nov 24, 2016 at 11:16 PM, odd hogstad 
wrote:

> db1 holds the auth stuff already. Do I need to also have it in db2 for the
> migrations to work?
>
> torsdag 24. november 2016 12.22.14 UTC+1 skrev pradam.programming følgende:
>>
>> hi Hogstad,
>> Before doing app migrate please python manage.py migrate auth ==>I hope
>> this will solve the issue
>>
>> On Thu, Nov 24, 2016 at 3:54 PM, odd hogstad  wrote:
>>
>>> I have two databases in my project, db1, which changes quite frequently,
>>> and db2, which seldom changes. The app was original written in django 1.3,
>>> but we've upgraded since then, and now uses 1.8. Now I need to make a
>>> change on db2 for the first time since the upgrade from 1.3. I make my
>>> changes in the model, but when I do python manage.py migrate model_of_db2
>>> db2, the changes seems to be applyed, but I get an error:
>>>
>>>
>>> "Error creating new content types. Please make sure contenttypes "
>>>
>>> RuntimeError: Error creating new content types. Please make sure
>>> contenttypes is migrated before trying to migrate apps individually.
>>>
>>>
>>> I tried adding a router, but same issue. What am I doing wrong? Do I
>>> need contenttypes also in db2?
>>>
>>>
>>> Thanks!
>>>
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/844ea033-380b-4103-86cc-311aec9f5abd%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+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/4dc7af3b-61d9-4128-b44a-ffbb5954214f%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+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/CAGGVXBP2mP-KWHeBHr%3DG480mrCokUOc0i9h9%3Dr2ns0%3D5YoEkSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations and multiple databases

2016-11-24 Thread odd hogstad
db1 holds the auth stuff already. Do I need to also have it in db2 for the 
migrations to work?

torsdag 24. november 2016 12.22.14 UTC+1 skrev pradam.programming følgende:
>
> hi Hogstad,
> Before doing app migrate please python manage.py migrate auth ==>I hope 
> this will solve the issue
>
> On Thu, Nov 24, 2016 at 3:54 PM, odd hogstad  > wrote:
>
>> I have two databases in my project, db1, which changes quite frequently, 
>> and db2, which seldom changes. The app was original written in django 1.3, 
>> but we've upgraded since then, and now uses 1.8. Now I need to make a 
>> change on db2 for the first time since the upgrade from 1.3. I make my 
>> changes in the model, but when I do python manage.py migrate model_of_db2 
>> db2, the changes seems to be applyed, but I get an error: 
>>
>>
>> "Error creating new content types. Please make sure contenttypes "
>>
>> RuntimeError: Error creating new content types. Please make sure 
>> contenttypes is migrated before trying to migrate apps individually.
>>
>>
>> I tried adding a router, but same issue. What am I doing wrong? Do I need 
>> contenttypes also in db2?
>>
>>
>> Thanks!
>>
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/844ea033-380b-4103-86cc-311aec9f5abd%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+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/4dc7af3b-61d9-4128-b44a-ffbb5954214f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations and multiple databases

2016-11-24 Thread pradam programming
hi Hogstad,
Before doing app migrate please python manage.py migrate auth ==>I hope
this will solve the issue

On Thu, Nov 24, 2016 at 3:54 PM, odd hogstad 
wrote:

> I have two databases in my project, db1, which changes quite frequently,
> and db2, which seldom changes. The app was original written in django 1.3,
> but we've upgraded since then, and now uses 1.8. Now I need to make a
> change on db2 for the first time since the upgrade from 1.3. I make my
> changes in the model, but when I do python manage.py migrate model_of_db2
> db2, the changes seems to be applyed, but I get an error:
>
>
> "Error creating new content types. Please make sure contenttypes "
>
> RuntimeError: Error creating new content types. Please make sure
> contenttypes is migrated before trying to migrate apps individually.
>
>
> I tried adding a router, but same issue. What am I doing wrong? Do I need
> contenttypes also in db2?
>
>
> Thanks!
>
>
> --
> 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/844ea033-380b-4103-86cc-311aec9f5abd%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+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/CAGGVXBPzDDRxVncagDh25D_ObuACaRApzXbwJhzOo3ykH6Dm5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Migrations and multiple databases

2016-11-24 Thread odd hogstad
I have two databases in my project, db1, which changes quite frequently, 
and db2, which seldom changes. The app was original written in django 1.3, 
but we've upgraded since then, and now uses 1.8. Now I need to make a 
change on db2 for the first time since the upgrade from 1.3. I make my 
changes in the model, but when I do python manage.py migrate model_of_db2 
db2, the changes seems to be applyed, but I get an error: 


"Error creating new content types. Please make sure contenttypes "

RuntimeError: Error creating new content types. Please make sure 
contenttypes is migrated before trying to migrate apps individually.


I tried adding a router, but same issue. What am I doing wrong? Do I need 
contenttypes also in db2?


Thanks!


-- 
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/844ea033-380b-4103-86cc-311aec9f5abd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


multiple databases - two questions

2016-11-03 Thread Mike Dewhirst

(this one might be easier to read)

I am planning some utility helper code to push selected records and 
their children from our staging database into the production database. 
The current database would be 'default' and I could add a second one 
called 'production' then read from 'default' and write to 'production'. 
(I need to check we are on the staging server).


The docs say ...

https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-managers-with-multiple-databases 



... but I don't quite understand. There are no custom managers involved; 
only the out-of-the-box MyModel.objects.


Q1. Should I be using db_manager()?

The plan is to write some utility code like this ...

from substance.models import Substance

def
write_substance_to_production(subst):

prd_subst, create =
Substance.objects.using('production').get_or_create(

name=subst.name,

)

if create:

pass

# copy all subst attributes except id to prd_subst


Q2. Is this a reasonable approach?

Thanks for any hints

Mike

--
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/15d2e5f8-48cc-b87c-d375-ce03b631fa10%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


multiple databases - two questions

2016-11-03 Thread Mike Dewhirst
I am planning some utility helper code to push selected records and 
their children from our staging database into the production database. 
The current database would be 'default' and I could add a second one 
called 'production' then read from 'default' and write to 'production'. 
(I need to check we are on the staging server).


The docs say ...

https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-managers-with-multiple-databases

... but I don't quite understand. There are no custom managers involved; 
only the out-of-the-box MyModel.objects.


Q1. Should I be using db_manager()?

The plan is to write some utility code like this ...

from substance.models import Substance def 
write_substance_to_production(subst): prd_subst, create = 
Substance.objects.using('production').get_or_create( name=subst.name, ) 
if create: pass # copy all subst attributes except id to prd_subst


Q2. Is this a reasonable approach?

Thanks for any hints

Mike



--
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/4a36d7aa-63d7-14b5-b342-76d259e114e7%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations with multiple databases

2016-10-27 Thread marcin . j . nowak


On Tuesday, October 25, 2016 at 5:05:46 PM UTC+2, andrea crotti wrote:
>
> We have a couple of databases with a tiny number of tables, but 
> django-migrations has still go through all the migrations anyway.
> So even if the SQL itself is nothing it still takes a massive amount of 
> time and memory for the usual known issues with migrations on big projects.
>
>
Hi Andrea.

I can suggest you switching to external db migration tool. The Liquibase 
works for me and my team for years in a quite big projects.

There is a Liquibase adapter for Django - Liquimigrate 
, which wraps cmd execution 
using connections defined in settings.DATABASES, and bypasses original 
"migrate" management commands.

The downside is that you'll have no automatic changeset generation from 
Django models, you must be familiar with Liquibase changesets syntax (XML, 
JSON or plain SQL files), and it requires JRE. But the good side is that 
you have independent, powerfull and rock-solid db migration subsystem with 
multidb support. It's worth trying.

Marcin

-- 
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/5da3f01e-9c57-45af-a432-c729dab84060%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations with multiple databases

2016-10-27 Thread andrea crotti
Ah nice thanks Markus, however 

- different subsets of INSTALLED_APPS sounds a bit hacky, how would I do it 
anyway?
  checking in the settings which database is being migrated and providing a 
different list?
  Or any other way?

- MIGRATION_MODULES sounds a bit safer, but I'm not sure it gives the same 
advantage, since from my understanding django still has to go through all 
the apps for each db anyway right?

>From my understanding the INSTALLED_APPS would be a much bigger performance 
gain right?
thanks

On Tuesday, October 25, 2016 at 4:29:45 PM UTC+1, Markus Holtermann wrote:
>
> Hi Andrea, 
>
> If you have models that are entirely unrelated in different databases 
> you could use different values for INSTALLED_APPS to limit the apps 
> Django sees or by settings the values in the MIGRATION_MODULES dict to 
> None to tell Django that those apps don't have migrations. 
>
> Cheers, 
>
> /Markus 
>
> On Tue, Oct 25, 2016 at 08:05:46AM -0700, andrea crotti wrote: 
> >We have a couple of databases with a tiny number of tables, but 
> >django-migrations has still go through all the migrations anyway. 
> >So even if the SQL itself is nothing it still takes a massive amount of 
> >time and memory for the usual known issues with migrations on big 
> projects. 
> > 
> >I guess it works this way because it only knows at run time in the router 
> >if something should be done, however it's a bit odd. 
> > 
> >If we declared the models per database somehow statically, could we not 
> >just skip everything else? 
> > 
> >-- 
> >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...@googlegroups.com . 
> >To post to this group, send email to django...@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/f5340bbf-2247-4068-bd37-9f3a0faf23d4%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+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/27b7a52a-d7d5-47b0-be8f-643af74379ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrations with multiple databases

2016-10-25 Thread Markus Holtermann

Hi Andrea,

If you have models that are entirely unrelated in different databases
you could use different values for INSTALLED_APPS to limit the apps
Django sees or by settings the values in the MIGRATION_MODULES dict to
None to tell Django that those apps don't have migrations.

Cheers,

/Markus

On Tue, Oct 25, 2016 at 08:05:46AM -0700, andrea crotti wrote:

We have a couple of databases with a tiny number of tables, but
django-migrations has still go through all the migrations anyway.
So even if the SQL itself is nothing it still takes a massive amount of
time and memory for the usual known issues with migrations on big projects.

I guess it works this way because it only knows at run time in the router
if something should be done, however it's a bit odd.

If we declared the models per database somehow statically, could we not
just skip everything else?

--
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/f5340bbf-2247-4068-bd37-9f3a0faf23d4%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+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/20161025152909.GE2361%40inel.local.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


Migrations with multiple databases

2016-10-25 Thread andrea crotti
We have a couple of databases with a tiny number of tables, but 
django-migrations has still go through all the migrations anyway.
So even if the SQL itself is nothing it still takes a massive amount of 
time and memory for the usual known issues with migrations on big projects.

I guess it works this way because it only knows at run time in the router 
if something should be done, however it's a bit odd.

If we declared the models per database somehow statically, could we not 
just skip everything else?

-- 
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/f5340bbf-2247-4068-bd37-9f3a0faf23d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Test cases are always referring to default database in case of Multiple databases

2016-06-08 Thread vaibhav
Hi,
I am trying to run some test cases on one of the apps of my Django Project.
My settings.py file specifies two different databases as follows:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'guest': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.guest.sqlite3'),
}
}


My models are as follows:

class Industry(AbstractTimestampClass):
name = models.CharField(max_length=100, unique=True)

def __str__(self):
return self.name

def __unicode__(self):
return self.name

class Meta:
verbose_name_plural = "Industries"



class Aim(AbstractTimestampClass):
name = models.CharField(max_length=100, unique=True)
icon = models.CharField(max_length=255)

def __str__(self):
return self.name

def __unicode__(self):
return self.name


class Campaign(AbstractTimestampClass):
website = models.CharField(max_length=255)
industry = models.ManyToManyField(Industry,   
related_name='related_industry_guest_campaigns')
aim = models.ManyToManyField(Aim, 
related_name='related_aim_guest_campaigns')
tracking_id = models.CharField(max_length=50, null=True, 
blank=True, db_index=True)

def save(self, *args, **kwargs):
'''add custom events while saving category'''
if self.id is None:
self.tracking_id = str(uuid.uuid4())
super(Campaign, self).save(*args, **kwargs)

def __str__(self):
return str(self.id)

def __unicode__(self):
return str(self.id)

My serializer is as follows:

class GuestCampaignSerializer(serializers.ModelSerializer):
class Meta:
model = Campaign
fields = ('website', 'tracking_id', 'industry', 'aim',   
 'created_on')

def validate(self, data):
if data['website']:
parsed_url = urlparse(data['website'])
data['website'] = parsed_url.scheme + '://' + 
 parsed_url.netloc
return data

def create(self, validated_data):
try:
campaign = 
Campaign.objects.using('guest').create(website=validated_data['website'])
campaign.save(using='guest')
campaign.aim.clear()
campaign.aim.set(validated_data['aim'],using='guest')
campaign.industry.clear()

campaign.industry.set(validated_data['industry'],using='guest')
return campaign
except Exception as e:
print "Exception in GuestCampaignSerializer - " + str(e)


The view is as follows:

class GuestCampaignViewSet(APIView):
permission_classes = (permissions.AllowAny,)
serializer = GuestCampaignSerializer

def post(self, request):
'''
Create new guest variation
---
type:
website:
required: true
type: string

responseMessages:
-   code: 200
message: 
-   code: 400
message: Bad request

consumes:
- application/json

produces:
- application/json
'''
try: 
print "In Guest campaign create"
print Industry.objects.using('guest').all()
data = self.serializer(data=request.data)
if data.is_valid():
campaign_obj = data.save()

# save first page w.r.t newly created campaign info
page_obj = Page()
page_obj.url = request.data['website']
page_obj.campaign_id = campaign_obj.id
page_obj.save(using='guest')

return Response({
"campaign" : {
"tracking_id": data.data['tracking_id'],
},
"page":  {
   "id": page_obj.id,
},
}, status=status.HTTP_201_CREATED)
else:
return Response({
"error" : {
"message" : "Error while creating the Guest 
Campaign",
"details" : data.errors
}
}, status=status.HTTP_400_BAD_REQUEST)

except Exception as e:
return Response({
"details": str(e)
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)


The test case is as follows:


Applying migrations to multiple databases in django?

2016-04-07 Thread Amir Meirbekov
Please, take a look at this question 
<http://stackoverflow.com/questions/36469216/applying-migrations-to-multiple-databases-in-django>.
 
Spent whole day screening source code, but still can't figure out the 
problem.


-- 
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/3559324e-c23b-4755-b6a2-0bdaed7ae711%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread 'Vinay Sajip' via Django users
Dear Carl,

On Tuesday, February 2, 2016 at 7:51:20 PM UTC, Carl Meyer wrote:
>
>
> There's nothing wrong with connections[options.get('database')] if you 
> want to get a specific database connection object; that's public API and 
> you can use it. In the case of the built-in commands, that's useful 
>

OK, perhaps I misunderstood what you said in an earlier comment - I see you 
were talking against using the *internals* of the connection rather the 
connection itself.

because they need to do low-level things with the connection; I don't 
> think it helps you for regular ORM use. It doesn't allow changing the 
> default connection for ORM usage. Where the built-in management commands 
> do use the higher-level ORM, they use the public `using` APIs. 
>
 
That's fine for simple use, but it's not good have lots of using() calls 
for models when it's not a "real" multi-DB scenario,
 

> If you want to write a management command that has a --database option 
> like the built-in ones and makes heavy use of the ORM, you can a) 
> explicitly provide `using` where needed , b) use 
> django-dynamic-db-router, or c) hold your nose and monkeypatch 
> DEFAULT_DB_ALIAS, since it's just a one-shot management command and you 
> don't need to be as concerned about cleaning up after yourself. 
>
> Personally I would go for (a) or (b), depending on just how much I was 
> using the ORM in the management command. I'm not convinced that a fourth 
> (or third supported public) option is necessary here. If it's just a few 
> queries, you use `using`, if it's more than that and you want a broader 
> policy applied, you use a database router. 
>
 
OK, thanks for the suggestion - you've been very helpful, as always. I'll 
mull things over and see what's the best for the specifics of the specific 
project.

Regards,

Vinay Sajip

-- 
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/832b093d-1d5a-4d24-9125-9eeb9297bbd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread Carl Meyer
Hi Vinay,

On 02/02/2016 12:14 PM, 'Vinay Sajip' via Django users wrote:
> I'm not arguing for any particular different routing scheme to be
> included - only for management commands to be able to be written to
> respect --data arguments passed to them, and which can easily treat the
> passed value as the default database to use just for that command
> invocation, when that value is different to whatever
> settings.DATABASES['default'] is. A quick look at the builtin management
> commands shows there's a lot of usage
> of connections[options.get('database')] going on, and yet externally
> written management commands aren't encouraged to use the same approach,
> and multiple settings files are the suggested alternative?

There's nothing wrong with connections[options.get('database')] if you
want to get a specific database connection object; that's public API and
you can use it. In the case of the built-in commands, that's useful
because they need to do low-level things with the connection; I don't
think it helps you for regular ORM use. It doesn't allow changing the
default connection for ORM usage. Where the built-in management commands
do use the higher-level ORM, they use the public `using` APIs.

In other words, the built-in management commands aren't doing anything
different from what I originally recommended you do (just use `using`).

If you want to write a management command that has a --database option
like the built-in ones and makes heavy use of the ORM, you can a)
explicitly provide `using` where needed , b) use
django-dynamic-db-router, or c) hold your nose and monkeypatch
DEFAULT_DB_ALIAS, since it's just a one-shot management command and you
don't need to be as concerned about cleaning up after yourself.

Personally I would go for (a) or (b), depending on just how much I was
using the ORM in the management command. I'm not convinced that a fourth
(or third supported public) option is necessary here. If it's just a few
queries, you use `using`, if it's more than that and you want a broader
policy applied, you use a database router.

Carl

-- 
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/56B10877.10900%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread 'Vinay Sajip' via Django users
Dear Carl,

On Tuesday, February 2, 2016 at 6:23:34 PM UTC, Carl Meyer wrote:
>
> For this scenario, I would use a different settings file (which can all 
> "inherit" the same common settings via the `from common_settings import 
> *` trick) for each "customer", with a different default database defined 
> in each. In fact, is there any reason for one process to have access to 
> another process' database at all, in your scenario? I don't think you 
> even have a use-case for Django's multi-db support here at all, just a 
> use case for multiple settings file variants. Then you can use the 
> --settings option with management commands to choose which settings to 
> use (or the DJANGO_SETTINGS_MODULE env var where that's convenient); you 
> don't need to define your own custom option. 


You're right, of course, this is a viable option.

 Django's multi-db support is designed for what you're calling "run-time 

routing," where a single process needs to access multiple different 
> databases at different times. That's not your situation; I'm not sure 
> you even need or want multi-db. 
>

No, we were looking at it as a possible convenient way of configuring 
things, but then again, perhaps not ;-)
 

> The "design flaw" you are observing here is not specific to databases, 
> but to Django settings. Django settings in general are not designed to 
> be modified at runtime; they define a static configuration for a given 
> process. Some settings can in practice safely be modified on-the-fly 
> (but still probably shouldn't be), some cannot, because their value is 
> cached for efficiency or other reasons: in general modifying settings at 
> runtime is not a supported technique. And it's not a _necessary_ 
> technique either, in your case, when you could just instead use the 
> right settings for each process from the beginning. 
>

Yes, but a management command run *is* a process run, and having read 
documentation and examples saying that you can pass --data to commands to 
operate on a particular database, it doesn't seem to be working as 
expected/advertised. Obviously there are many ways to skin this particular 
cat, including using multiple setting files, which we of course do for 
things like dev vs. test vs. production etc. The idea was that we could use 
a special settings file just for populating customer databases, with a 
common set of settings ... of course we can use the usual technique of 
"inheriting" settings from other modules, and so on.

> I suppose I 
> > was expecting transaction.atomic(using=XXX) to not just open a 
> > transaction on that database, but also make it the default for the scope 
> > of the block (except if explicitly overridden by using() for particular 
> > models in code called from that block). The current behaviour seems to 
> > violate the principle of least surprise (this my first encounter with 
> > multiple databases). 
>
> I think Django's design in this case is superior to the one you propose, 
> because it keeps two concepts orthogonal that don't need to be linked 
> (transactions and multi-db-routing) and avoids implicit global or 
> thread-local state changes in operations that don't obviously imply such 
> changes, making the overall system more flexible and predictable. 
>
> I suppose we'd need a more scientific survey to establish which behavior 
> is more surprising to more people :-) 
>

Note that my post is about management commands, specifically. In a multi-DB 
situation, there could well be times when you want specific management 
commands to run against different databases each time they're invoked. What 
you are saying is that this can't be done using a --data argument to the 
command, where there are typically no issues of thread-locality or the need 
to dynamically route to DBs based on HTTP requests or models. Not a very 
common use case, to be sure, but not especially esoteric, either. It seems 
there is no way to do this in the most natural-seeming way (--data)  with 
Django out-of-the-box - if I understand you correctly, you would have to 
set up multiple settings files, one for each database, where the *only* 
difference would the the value of DATABASES['default'] in that settings 
file from all the other settings files created for this purpose, and then 
invoke that using DJANGO_SETTINGS_MODULE= the particular settings file for 
database you wanted to operate on for that run. Possible to do, of course, 
but it feels like a workaround rather than a natural approach.

> Is there really no case for an in_database() 
> > context manager in Django itself? 
>
> Perhaps. In my experience the more typical uses for multi-db are 
> amenable to other types of routing (e.g. models X, Y are always routed 
> to database A, model Z is always rout

Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread Carl Meyer
Hi Vinay,

On 02/02/2016 10:56 AM, 'Vinay Sajip' via Django users wrote:
> On Tuesday, February 2, 2016 at 5:08:40 PM UTC, Carl Meyer wrote: 
> 
> You can't (well, you might be able to by poking around in the internals
> of the django.db.connections object, but I'd strongly advise against
> that). The proper (and thread-safe) way to achieve the equivalent is to
> 
> Well, for any given run of the application (on which the example I
> posted is based), only one database is ever used. The idea of multiple
> databases was to allow us to select which one is used for any particular
> Python process run, and we expected to be able to run management
> commands which would (based on a settings configuration) determine both
> which database to use and e.g. how to populate parts of it ready for
> deployment to particular customers.

For this scenario, I would use a different settings file (which can all
"inherit" the same common settings via the `from common_settings import
*` trick) for each "customer", with a different default database defined
in each. In fact, is there any reason for one process to have access to
another process' database at all, in your scenario? I don't think you
even have a use-case for Django's multi-db support here at all, just a
use case for multiple settings file variants. Then you can use the
--settings option with management commands to choose which settings to
use (or the DJANGO_SETTINGS_MODULE env var where that's convenient); you
don't need to define your own custom option.

Django's multi-db support is designed for what you're calling "run-time
routing," where a single process needs to access multiple different
databases at different times. That's not your situation; I'm not sure
you even need or want multi-db.

> Oddly, setting
> django.db.utils.DEFAULT_DB_ALIAS = alias does the trick. Yes, I know
> that's a no-no, but it seems to me that for this kind of case where you
> don't need run-time routing, something like django-dynamic-db-router
> shouldn't really be needed, useful though it might be for the run-time
> routing case. Everything else works off the settings module, and the
> fact that Django caches the default database to use such that a
> management command can't change it seems like a design flaw.

The "design flaw" you are observing here is not specific to databases,
but to Django settings. Django settings in general are not designed to
be modified at runtime; they define a static configuration for a given
process. Some settings can in practice safely be modified on-the-fly
(but still probably shouldn't be), some cannot, because their value is
cached for efficiency or other reasons: in general modifying settings at
runtime is not a supported technique. And it's not a _necessary_
technique either, in your case, when you could just instead use the
right settings for each process from the beginning.

> I suppose I
> was expecting transaction.atomic(using=XXX) to not just open a
> transaction on that database, but also make it the default for the scope
> of the block (except if explicitly overridden by using() for particular
> models in code called from that block). The current behaviour seems to
> violate the principle of least surprise (this my first encounter with
> multiple databases).

I think Django's design in this case is superior to the one you propose,
because it keeps two concepts orthogonal that don't need to be linked
(transactions and multi-db-routing) and avoids implicit global or
thread-local state changes in operations that don't obviously imply such
changes, making the overall system more flexible and predictable.

I suppose we'd need a more scientific survey to establish which behavior
is more surprising to more people :-)

> Is there really no case for an in_database()
> context manager in Django itself?

Perhaps. In my experience the more typical uses for multi-db are
amenable to other types of routing (e.g. models X, Y are always routed
to database A, model Z is always routed to database B, or more complex
schemes), and dynamically-scoped routing (such as that provided by
`in_database`) isn't as commonly needed.

Django provides the database router abstraction, which is a very
flexible system for implementing whatever kind of multi-db routing you
need. The burden of proof is heavy on any particular routing scheme to
demonstrate that it is so frequently needed that it should be bundled
with Django itself, rather than being a separate reusable package for
those who need it.

Carl

-- 
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://gro

Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread 'Vinay Sajip' via Django users
Dear Carl,

On Tuesday, February 2, 2016 at 5:08:40 PM UTC, Carl Meyer wrote: 
>
> You can't (well, you might be able to by poking around in the internals 
> of the django.db.connections object, but I'd strongly advise against 
> that). The proper (and thread-safe) way to achieve the equivalent is to 
>

Well, for any given run of the application (on which the example I posted 
is based), only one database is ever used. The idea of multiple databases 
was to allow us to select which one is used for any particular Python 
process run, and we expected to be able to run management commands which 
would (based on a settings configuration) determine both which database to 
use and e.g. how to populate parts of it ready for deployment to particular 
customers. Oddly, setting django.db.utils.DEFAULT_DB_ALIAS = alias does the 
trick. Yes, I know that's a no-no, but it seems to me that for this kind of 
case where you don't need run-time routing, something like 
django-dynamic-db-router shouldn't really be needed, useful though it might 
be for the run-time routing case. Everything else works off the settings 
module, and the fact that Django caches the default database to use such 
that a management command can't change it seems like a design flaw. I 
suppose I was expecting transaction.atomic(using=XXX) to not just open a 
transaction on that database, but also make it the default for the scope of 
the block (except if explicitly overridden by using() for particular models 
in code called from that block). The current behaviour seems to violate the 
principle of least surprise (this my first encounter with multiple 
databases). Is there really no case for an in_database() context manager in 
Django itself? Though I would still expect that behaviour from 
transaction.atomic(), of course, but backwards compatibility is a 
constraint I'm aware of :-)

Regards,

Vinay Sajip

-- 
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/66079ae6-f7e8-4771-acd0-30537bcb1c84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread Carl Meyer
Hi Vinay,

On 02/02/2016 09:52 AM, 'Vinay Sajip' via Django users wrote:
> 
> On Tuesday, February 2, 2016 at 3:27:10 PM UTC, Carl Meyer wrote:
> 
> Nothing in your code ever "overrides" settings.DATABASES['default'].
> 
> 
> Dear Carl,
> 
> Thanks for the quick response. I /had/ thought of that, and tried adding
> the statement settings.DATABASES['default'] = settings.DATABASES[alias]
> just before the with block, and it had no effect - the result was the
> same - so I took it out. How else are you supposed to override the
> default database?

You can't (well, you might be able to by poking around in the internals
of the django.db.connections object, but I'd strongly advise against
that). The proper (and thread-safe) way to achieve the equivalent is to
do what the third-party project I linked (django-dynamic-db-router)
does: write a db router that references some thread-local state to
determine which database to route queries to, and write a context
manager or whatever to modify that thread-local state. Or just use
django-dynamic-db-router, since it already does what you want :-)

Carl

-- 
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/56B0E273.8070604%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread 'Vinay Sajip' via Django users

On Tuesday, February 2, 2016 at 3:27:10 PM UTC, Carl Meyer wrote:
>
> Nothing in your code ever "overrides" settings.DATABASES['default']. 
>

Dear Carl,

Thanks for the quick response. I *had* thought of that, and tried adding 
the statement settings.DATABASES['default'] = settings.DATABASES[alias] 
just before the with block, and it had no effect - the result was the same 
- so I took it out. How else are you supposed to override the default 
database?

Regards,

Vinay Sajip

-- 
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/39fea9af-584b-45e2-b8c8-dec665f0bd2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread Carl Meyer
Hi Vinay,

On 02/02/2016 08:11 AM, 'Vinay Sajip' via Django users wrote:
> I've set up a simple project using with two databases, foo and bar in
> settings.py:
> 
> |
> DATABASES ={
> 'foo':{
> 'ENGINE':'django.db.backends.sqlite3',
> 'NAME':os.path.join(BASE_DIR,'foo.sqlite'),
> },
> 'bar':{
> 'ENGINE':'django.db.backends.sqlite3',
> 'NAME':os.path.join(BASE_DIR,'bar.sqlite'),
> }
> }
> DATABASES['default']=DATABASES['foo']
> 
> |
> 
> I have a simple model:
> 
> |
> classThing(models.Model):
> name =models.CharField(max_length=20,unique=True)
> |
> 
> I have a simple management command:
> 
> |
> classCommand(BaseCommand):
> help ='Add all the things.'
> 
> 
> defadd_arguments(self,parser):
> parser.add_argument('--database',nargs='?',metavar='DATABASE',
> default='default',
> help='Database alias to use')
> parser.add_argument('things',nargs='+',metavar='THING',
> help='Things to add')
> 
> 
> defhandle(self,*args,**options):
> alias=options['database']
> self.stdout.write('using alias %s'%alias)
> withtransaction.atomic(using=alias):
> forname inoptions['things']:
> try:
> Thing.objects.create(name=name)
> self.stdout.write('Added %s.\n'%name)
> exceptIntegrityErrorase:
> self.stderr.write('Failed to add thing %r: %s'%(name,e))
> break
> |
> 
> After running migrations to set up the two databases, using python
> manage.py migrate --data foo and python manage.py migrate --data bar, I
> then run python manage.py add_things fizz buzz which results in two
> records being added to foo.sqlite, as expected. 
> 
> If I then run python manage.py add_things fizz buzz --data bar, it seems
> reasonable to expect it to add the records to bar.sqlite. However, this
> is not what happens: it tries to add them to foo.sqlite, even though
> I've specified using=alias with the alias set to bar. So I get a
> constraint violation:
> 
> |
> usingaliasbar
> Failedto add thing 'fizz':UNIQUE constraint failed:hello_thing.name
> |
> 
> What have I overlooked? In a real case the atomic block might be
> manipulating lots of models in nested code, and I can't see that it's
> practical to call using() for every model. Somewhere, it looks like
> Django code is caching a connection based on what
> settings.DATABASES['default'] was when settings was imported, even
> though it is being overridden in the command line. If not actually a
> bug, this behaviour doesn't seem particularly intuitive, so any advice
> would be gratefully received.

Nothing in your code ever "overrides" settings.DATABASES['default'].
Defining an atomic block on a certain database has no effect on the
default database within that block, it just opens a transaction on the
requested database. "Which database is default" and "which database(s)
has/have transactions open on them" are completely orthogonal questions,
there is no implicit link between them. Nothing prevents you from having
simultaneous transactions open on multiple databases, and interspersing
queries to different databases while those transactions are open.

If calling .using() explicitly to use a non-default database is
burdensome (and the situation can't be handled automatically with a
custom database router class), you could look at a third-party solution
like django-dynamic-db-router [1], which provides an `in_database`
context manager that does what you were expecting `transactions.atomic`
to do for you.

Carl

[1]
https://github.com/ambitioninc/django-dynamic-db-router/blob/master/docs/quickstart.rst

-- 
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/56B0CA99.2090308%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Unintuitive behaviour of management commands with multiple databases

2016-02-02 Thread 'Vinay Sajip' via Django users
I've set up a simple project using with two databases, foo and bar in 
settings.py:

DATABASES = {
'foo': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'foo.sqlite'),
},
'bar': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'bar.sqlite'),
}
}
DATABASES['default'] = DATABASES['foo']


I have a simple model:

class Thing(models.Model):
name = models.CharField(max_length=20, unique=True)

I have a simple management command:

class Command(BaseCommand):
help = 'Add all the things.'


def add_arguments(self, parser):
parser.add_argument('--database', nargs='?', metavar='DATABASE',
default='default',
help='Database alias to use')
parser.add_argument('things', nargs='+', metavar='THING',
help='Things to add')


def handle(self, *args, **options):
alias = options['database']
self.stdout.write('using alias %s' % alias)
with transaction.atomic(using=alias):
for name in options['things']:
try:
Thing.objects.create(name=name)
self.stdout.write('Added %s.\n' % name)
except IntegrityError as e:
self.stderr.write('Failed to add thing %r: %s' % (name, 
e))
break

After running migrations to set up the two databases, using python 
manage.py migrate --data foo and python manage.py migrate --data bar, I 
then run python manage.py add_things fizz buzz which results in two records 
being added to foo.sqlite, as expected. 

If I then run python manage.py add_things fizz buzz --data bar, it seems 
reasonable to expect it to add the records to bar.sqlite. However, this is 
not what happens: it tries to add them to foo.sqlite, even though I've 
specified using=alias with the alias set to bar. So I get a constraint 
violation:

using alias bar
Failed to add thing 'fizz': UNIQUE constraint failed: hello_thing.name

What have I overlooked? In a real case the atomic block might be 
manipulating lots of models in nested code, and I can't see that it's 
practical to call using() for every model. Somewhere, it looks like Django 
code is caching a connection based on what settings.DATABASES['default'] 
was when settings was imported, even though it is being overridden in the 
command line. If not actually a bug, this behaviour doesn't seem 
particularly intuitive, so any advice would be gratefully received.

Regards,

Vinay Sajip

-- 
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/c61ddb5b-a5cb-460d-a109-b30ccd7d2a78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple databases in Django 1.7

2015-12-09 Thread Łukasz Pauszek
Hey,
thank you for fast response.
Yes, I'm aware that allow_migrate format from the one mentioned in link you 
provided because (as is mentioned in title) I'm using 
Django 1.7 and the code I provided is almost copy/paste of what you can 
find under the same link but for v. 1.7
Things I changed in code are data base name and _meta.app_label

W dniu środa, 9 grudnia 2015 22:35:58 UTC+1 użytkownik learn django napisał:
>
> Hi LP.
>
> Your allow_migrate function differs in the format from what is mentioned 
> in the link below.
>
> https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing
>
> I have tried this last week and it works fine.
>
> On Wednesday, December 9, 2015 at 2:47:42 AM UTC-8, Łukasz Pauszek wrote:
>>
>> Hello,
>> I'm trying to configure project in Django 1.7 to use multiple databases, 
>> for now I'm following official documentation to configure 2 dbs. 
>> Problem is that when I run: ./manage.py makemigrations myapp only changes 
>> in default database are detected. And ./manage.py migrate 
>> --database=main_db doesn't see model which should be created in it. 
>> What should I do to update second database?
>> Below I'm pasting code which I think may be relevant:
>>
>> project/settings.py
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.sqlite3',
>> 'NAME': os.path.join(BASE_DIR, 'default.sqlite3'),
>> },
>> 'main_db': {
>> 'ENGINE': 'django.db.backends.sqlite3',
>> 'NAME': os.path.join(BASE_DIR, 'main_db.sqlite3')
>> }
>> }
>>
>> DATABASE_ROUTERS = ['myapp.routers.SelectDatabaseRouter']
>>
>> myapp/models.py
>> class TestingDefaultDatabase(models.Model):
>>
>> class Meta:
>> verbose_name = "TestingDefaultDatabase"
>> verbose_name_plural = "TestingDefaultDatabases"
>>
>> name = models.CharField(max_length=50)
>> surname = models.CharField(max_length=50)
>>
>>
>> class TestingMainDatabase(models.Model):
>>
>> class Meta:
>> verbose_name = "TestingMainDatabase"
>> verbose_name_plural = "TestingMainDatabases"
>> app_label = 'main'
>>
>> name = models.CharField(max_length=50)
>> surname = models.CharField(max_length=50)
>>
>> myapp/routers.py
>> class SelectDatabaseRouter(object):
>> def db_for_read(self, model, **hints):
>> if model._meta.app_label == 'main':
>> return 'main_db'
>> return None
>>
>> def db_for_write(self, model, **hints):
>> if model._meta.app_label == 'main':
>> return 'main_db'
>> return None
>>
>> def allow_relation(self, obj1, obj2, **hints):
>> if obj1._meta.app_label == 'main' or \
>> obj2._meta.app_label == 'main':
>> return True
>> return None
>>
>> def allow_migrate(self, db, model):
>> if db == 'main_db':
>> return model._meta.app_label == 'main'
>> elif model._meta.app_label == 'main':
>> return False
>> return None
>>
>> Am I missing or incorrectly configured something? Or perhaps I'm not 
>> using appropriate commands?
>> Thank you for help.
>> ŁP
>>
>

-- 
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/a57a9b99-e185-4751-9f73-910198473caa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple databases in Django 1.7

2015-12-09 Thread learn django
Hi LP.

Your allow_migrate function differs in the format from what is mentioned in 
the link below.
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#topics-db-multi-db-routing

I have tried this last week and it works fine.

On Wednesday, December 9, 2015 at 2:47:42 AM UTC-8, Łukasz Pauszek wrote:
>
> Hello,
> I'm trying to configure project in Django 1.7 to use multiple databases, 
> for now I'm following official documentation to configure 2 dbs. 
> Problem is that when I run: ./manage.py makemigrations myapp only changes 
> in default database are detected. And ./manage.py migrate 
> --database=main_db doesn't see model which should be created in it. 
> What should I do to update second database?
> Below I'm pasting code which I think may be relevant:
>
> project/settings.py
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.sqlite3',
> 'NAME': os.path.join(BASE_DIR, 'default.sqlite3'),
> },
> 'main_db': {
> 'ENGINE': 'django.db.backends.sqlite3',
> 'NAME': os.path.join(BASE_DIR, 'main_db.sqlite3')
> }
> }
>
> DATABASE_ROUTERS = ['myapp.routers.SelectDatabaseRouter']
>
> myapp/models.py
> class TestingDefaultDatabase(models.Model):
>
> class Meta:
> verbose_name = "TestingDefaultDatabase"
> verbose_name_plural = "TestingDefaultDatabases"
>
> name = models.CharField(max_length=50)
> surname = models.CharField(max_length=50)
>
>
> class TestingMainDatabase(models.Model):
>
> class Meta:
> verbose_name = "TestingMainDatabase"
> verbose_name_plural = "TestingMainDatabases"
> app_label = 'main'
>
> name = models.CharField(max_length=50)
> surname = models.CharField(max_length=50)
>
> myapp/routers.py
> class SelectDatabaseRouter(object):
> def db_for_read(self, model, **hints):
> if model._meta.app_label == 'main':
> return 'main_db'
> return None
>
> def db_for_write(self, model, **hints):
> if model._meta.app_label == 'main':
> return 'main_db'
> return None
>
> def allow_relation(self, obj1, obj2, **hints):
> if obj1._meta.app_label == 'main' or \
> obj2._meta.app_label == 'main':
> return True
> return None
>
> def allow_migrate(self, db, model):
> if db == 'main_db':
> return model._meta.app_label == 'main'
> elif model._meta.app_label == 'main':
> return False
> return None
>
> Am I missing or incorrectly configured something? Or perhaps I'm not using 
> appropriate commands?
> Thank you for help.
> ŁP
>

-- 
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/a89f9477-2241-4fd4-8506-283602693953%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple databases in Django 1.7

2015-12-09 Thread Łukasz Pauszek
Hello,
I'm trying to configure project in Django 1.7 to use multiple databases, 
for now I'm following official documentation to configure 2 dbs. 
Problem is that when I run: ./manage.py makemigrations myapp only changes 
in default database are detected. And ./manage.py migrate 
--database=main_db doesn't see model which should be created in it. 
What should I do to update second database?
Below I'm pasting code which I think may be relevant:

project/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'default.sqlite3'),
},
'main_db': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'main_db.sqlite3')
}
}

DATABASE_ROUTERS = ['myapp.routers.SelectDatabaseRouter']

myapp/models.py
class TestingDefaultDatabase(models.Model):

class Meta:
verbose_name = "TestingDefaultDatabase"
verbose_name_plural = "TestingDefaultDatabases"

name = models.CharField(max_length=50)
surname = models.CharField(max_length=50)


class TestingMainDatabase(models.Model):

class Meta:
verbose_name = "TestingMainDatabase"
verbose_name_plural = "TestingMainDatabases"
app_label = 'main'

name = models.CharField(max_length=50)
surname = models.CharField(max_length=50)

myapp/routers.py
class SelectDatabaseRouter(object):
def db_for_read(self, model, **hints):
if model._meta.app_label == 'main':
return 'main_db'
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == 'main':
return 'main_db'
return None

def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == 'main' or \
obj2._meta.app_label == 'main':
return True
return None

def allow_migrate(self, db, model):
if db == 'main_db':
return model._meta.app_label == 'main'
elif model._meta.app_label == 'main':
return False
return None

Am I missing or incorrectly configured something? Or perhaps I'm not using 
appropriate commands?
Thank you for help.
ŁP

-- 
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/3033c961-efa9-4e3a-9dcf-e212b09fd222%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple databases

2015-05-19 Thread Galia Ladiray
It depends what you need,
We use redis for non sql, and postgres for sql,
You can use an id field to have a link between them.

Django 1.8 has a support for postgres specific fields like HStore, maybe 
this is good enough for you?
Galia

On Tuesday, May 19, 2015 at 2:40:17 AM UTC+2, Roger Dunn wrote:
>
> I'm spinning up a new project and nearly all of the data I need to store 
> can be normalized. Along with this normalized data is one piece that is 
> better suited to a nosql database. 
>
> The use case is that the normalized data will be fetched often, is very 
> tabular in nature, and the additional data is more document centric and 
> will be fetch less often, by quite a margin. 
>
> I'm thinking of doing a hybrid using the 2 technologies. There will be a 1 
> for 1 relationship by rows. I know I could do either nosql or mysql, but 
> for the exercise thinking of doing both. 
>
> Any examples floating around for this?
>

-- 
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/a77b0e65-2ace-417c-a555-a199fd6c7c20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple databases

2015-05-18 Thread Javier Guerra Giraldez
On Mon, May 18, 2015 at 7:35 PM, Roger Dunn  wrote:
> The use case is that the normalized data will be fetched often, is very
> tabular in nature, and the additional data is more document centric and will
> be fetch less often, by quite a margin.


have you considered PostgreSql?  it does handle json or xml documents
quite well (in fact, arguably better than most "document databases"
out there)

-- 
Javier

-- 
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/CAFkDaoS3rZwDOE%2BcMoE5V_VKz19nTA-jZj28QDicDEn_GkMepg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Multiple databases

2015-05-18 Thread Roger Dunn
I'm spinning up a new project and nearly all of the data I need to store 
can be normalized. Along with this normalized data is one piece that is 
better suited to a nosql database. 

The use case is that the normalized data will be fetched often, is very 
tabular in nature, and the additional data is more document centric and 
will be fetch less often, by quite a margin. 

I'm thinking of doing a hybrid using the 2 technologies. There will be a 1 
for 1 relationship by rows. I know I could do either nosql or mysql, but 
for the exercise thinking of doing both. 

Any examples floating around for this?

-- 
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/272ad26a-0ed5-478e-8da6-2c35646b68a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-21 Thread Luan Nguyen
Hi, sorry for my late response.

Thanks for replying.

I'm using django 1.7.4.

Going with this 
Room.objects.using('another').select_related('hotel').get(pk=10) is fine, I 
can then get room.hotel without any problem.

I also followed Jani's advice and changed default manager of Room to 
GeoManager, but still got that error.

@George: I actually had this issue in one of my app (running django 1.7), 
but not sure whether it's due to my code or django, so I set up a 
completely new project as described above (with django 1.7.4), and still 
get the error. Postgis is enabled on both databases (will get error if it 
doesn't anyway).

I was trying to trace back the code but don't have enough experience to 
fully understand the problem. I'll ask geodjango list as Collin suggested 
to see if someone experienced the same thing.

Luan

-- 
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/bebe1636-c8a8-4026-bb11-578f29220149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-20 Thread Jani Tiainen
On Wed, 18 Feb 2015 06:45:15 -0800 (PST)
Luan Nguyen <liha...@gmail.com> wrote:

> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
> 
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
> 
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
> 
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)

You don't have GeoManager on Room model? It's required to be default (first) 
manager if you do queries that even relate to geo-enabled model.

https://docs.djangoproject.com/en/1.7/ref/contrib/gis/model-api/#geomanager

And there reads: "It should also be noted that GeoManager is required even if 
the model does not have a geographic field itself, e.g., in the case of a 
ForeignKey relation to a model with a geographic field."
 
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id <http://h.room_set.all%28%29[0].id/> #=> room id 
> 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py>",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py>",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
> 
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
> 
> -- 
> 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/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150220101236.1c721b6e%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-19 Thread George Silva
I'm using with success two postgis enabled databases on a single
application, without quirks.

I have a read-only database, and a read/write database. No problems, so far.

On Thu, Feb 19, 2015 at 5:11 PM, Collin Anderson <cmawebs...@gmail.com>
wrote:

> Hi,
>
> Interesting. What version of django is this?
>
> Here's something to try:
> Room.objects.using('another').select_related('hotel').get(pk=10)
>
> It could very well be an issue with GeoManager / GeoQuerySet.
>
> You also could ask on the geodjango list to see if anyone else has run
> into that.
>
> http://groups.google.com/group/geodjango
>
> Collin
>
>
> On Wednesday, February 18, 2015 at 9:45:15 AM UTC-5, Luan Nguyen wrote:
>>
>> I'm using geodjango and multiple databases, and experiencing a quite
>> weird situation, I guess it's a kind of bug but not absolutely sure since
>> I'm pretty new to Django.
>>
>> Here is how to reproduce the problem:
>> - Set up another database besides default:
>> DATABASES = {
>> 'default': {
>> 'ENGINE' : 'django.contrib.gis.db.backends.postgis'
>> <http://django.contrib.gis.db.backends.postgis%27/>,
>> 'NAME' : 'issue1',
>> 'USER' : 'user',
>> 'PASSWORD' : 'password',
>> 'HOST' : '127.0.0.1',
>> 'OPTIONS' : {
>> 'autocommit' : True,
>> }
>> },
>> 'another': {
>> 'ENGINE' : 'django.contrib.gis.db.backends.postgis'
>> <http://django.contrib.gis.db.backends.postgis%27/>,
>> 'NAME' : 'issue2',
>> 'USER' : 'user',
>> 'PASSWORD' : 'password',
>> 'HOST' : '127.0.0.1',
>> 'OPTIONS' : {
>> 'autocommit' : True,
>> }
>> },
>> }
>>
>> And two models:
>> from django.db import models as default_models
>> from django.contrib.gis.db import models
>> # Create your models here.
>> class Hotel(models.Model):
>> hotel_name = models.CharField(max_length=255)
>> objects = models.GeoManager()
>>
>> class Room(models.Model):
>> room_num = models.IntegerField()
>> hotel = models.ForeignKey(Hotel, null=True, blank=True)
>>
>> Add data into issue2 database (leave issue1 blank), then go into shell:
>> >>>h = Hotel.objects.using('another').all()[0]
>> >>> h.id
>> 9
>> >>>h.room_set.all()[0].id #=> room id 10 links to hotel id 9
>> 10
>> >>>r = Room.objects.using('another').get(pk=10)
>> >>>r.hotel
>> Traceback (most recent call last):
>> File "", line 1, in 
>> File "/Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.
>> 4/site-packages/django/db/models/fields/related.py
>> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py>",
>> line 572, in __get__
>> rel_obj = qs.get()
>> File "/Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.
>> 4/site-packages/django/db/models/query.py
>> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py>",
>> line 357, in get
>> self.model._meta.object_name)
>> multi.models.DoesNotExist: Hotel matching query does not exist.
>>
>> The thing is, if I create a hotel record on database issue1 with id of 9
>> then the last command works, so I guess it tried to look up in default
>> database. This doesn't have any problems if I use default manager for
>> Hotel, so I guess it's a bug?
>>
>  --
> 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/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
George R. C. Silva
SIGMA Consultoria

http://www.consultoriasigma.com.br/

-- 
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/CAGyPVTuc5ecd-1xBvTT-_GKSbAAmGAgY_w0qSE6QptAfkoweYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-19 Thread Collin Anderson
Hi,

Interesting. What version of django is this?

Here's something to try:
Room.objects.using('another').select_related('hotel').get(pk=10)

It could very well be an issue with GeoManager / GeoQuerySet.

You also could ask on the geodjango list to see if anyone else has run into 
that.

http://groups.google.com/group/geodjango

Collin

On Wednesday, February 18, 2015 at 9:45:15 AM UTC-5, Luan Nguyen wrote:
>
> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
>
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
>
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
>
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)
>
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id #=> room id 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py>",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py>",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
>
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
>

-- 
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/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Seems like a geodjango bug with multiple databases

2015-02-18 Thread Luan Nguyen
I'm using geodjango and multiple databases, and experiencing a quite weird 
situation, I guess it's a kind of bug but not absolutely sure since I'm 
pretty new to Django.

Here is how to reproduce the problem:
- Set up another database besides default:
DATABASES = {
'default': {
'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
<http://django.contrib.gis.db.backends.postgis%27/>,
'NAME' : 'issue1',
'USER' : 'user',
'PASSWORD' : 'password',
'HOST' : '127.0.0.1',
'OPTIONS' : {
'autocommit' : True,
}
},
'another': {
'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
<http://django.contrib.gis.db.backends.postgis%27/>,
'NAME' : 'issue2',
'USER' : 'user',
'PASSWORD' : 'password',
'HOST' : '127.0.0.1',
'OPTIONS' : {
'autocommit' : True,
}
},
}

And two models:
from django.db import models as default_models
from django.contrib.gis.db import models
# Create your models here.
class Hotel(models.Model):
hotel_name = models.CharField(max_length=255)
objects = models.GeoManager()

class Room(models.Model):
room_num = models.IntegerField()
hotel = models.ForeignKey(Hotel, null=True, blank=True)

Add data into issue2 database (leave issue1 blank), then go into shell:
>>>h = Hotel.objects.using('another').all()[0]
>>> h.id
9
>>>h.room_set.all()[0].id <http://h.room_set.all%28%29[0].id/> #=> room id 
10 links to hotel id 9
10
>>>r = Room.objects.using('another').get(pk=10)
>>>r.hotel
Traceback (most recent call last):
File "", line 1, in 
File "/
Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
 
<http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py>",
 
line 572, in __get__
rel_obj = qs.get()
File "/
Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
 
<http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py>",
 
line 357, in get
self.model._meta.object_name)
multi.models.DoesNotExist: Hotel matching query does not exist.

The thing is, if I create a hotel record on database issue1 with id of 9 
then the last command works, so I guess it tried to look up in default 
database. This doesn't have any problems if I use default manager for 
Hotel, so I guess it's a bug?

-- 
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/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple databases and admin list_filter

2014-09-24 Thread Pam Suebvisai
Hi,

I'm trying to use multiple databases with the admin interface by separating 
the 2 databases to 2 admin sites following the example 
at 
https://docs.djangoproject.com/en/1.7/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface.
 
However, when I add list_filter into the admin class, it always gets the 
list to be used as the filter from the default database. Anybody else has 
this problem or know how to fix this?

Thanks,
Pam

-- 
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/42159863-c1c5-41f8-addb-3f20ebbbabf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Is it possible to get working django transaction with django multiple databases

2014-06-16 Thread Ilya Kazakevich
I believe you need software that supports distributed transaction coordination 
protocols ("X/Open XA" Is good example) and both DBs should support this 
protocol and two-phase commit.


Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"

>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of Juan Jose Huelga
>Sent: Monday, June 16, 2014 5:45 PM
>To: django-users@googlegroups.com
>Subject: Is it possible to get working django transaction with django multiple
>databases
>
>Hi there. I'm trying to get a django site working with multiple databases, it
>means a DB1 for django site an another existing DB2 (say a legacy BD) but I 
>need
>transactions enabled. I need to run queries over BD2 that depends on queries
>over DB1 and the other way around. If any of these queries fail, I need to 
>rollback
>all operations.
>
>I have read Django's documentation regarding Multiple databases and
>Transactions, but it is not clear to me if Django support transactions on 
>Multiple
>databases.
>
>Best Regards.
>
>--
>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/CA%2Bn%2BcA2C5C62ww9sB
>%3DdhY-DTujO_HibkY1tWnBLuuBgA1sHH6w%40mail.gmail.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+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/00bd01cf897d%2449d3ac40%24dd7b04c0%24%40JetBrains.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to get working django transaction with django multiple databases

2014-06-16 Thread Juan Jose Huelga
Hi there. I'm trying to get a django site working with multiple
databases, it means a DB1 for django site an another existing DB2 (say
a legacy BD) but I need transactions enabled. I need to run queries
over BD2 that depends on queries over DB1 and the other way around. If
any of these queries fail, I need to rollback all operations.

I have read Django's documentation regarding Multiple databases and
Transactions, but it is not clear to me if Django support transactions
on Multiple databases.

Best Regards.

-- 
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/CA%2Bn%2BcA2C5C62ww9sB%3DdhY-DTujO_HibkY1tWnBLuuBgA1sHH6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem with syncdb and multiple databases

2013-11-11 Thread Sells, Fred
I'm using Django 1.5 and Mysql 5.1 and am in the early stages of a multiple app 
development and the schema is changing frequently as "hidden" requirements 
emerge.  I cannot get syncdb to sync anything other than my default db, and 
when I change my default, it still seems to see the old one.   Here is 
settings.py, with some junk removed for brevity.  Routers.py is attached and is 
in the same directory as settings.  I cannot figure out what's going wrong with 
syncdb, but the normal application seems to work correctly.I had commented 
out the "allow_syncdb" in the routers because I could not get it to work, it 
seems to have some impact but not sure what.

settings.py=
DATABASES = {
'default': {'ENGINE': 'django.db.backends.mysql', 'NAME': 'accstaff'...
},
'wnr': {   'ENGINE': 'django.db.backends.mysql', NAME': 'wnr'...},
'accstaff': {'ENGINE': 'django.db.backends.mysql', 'NAME': 
'accstaff'...},
'inserv': {  'ENGINE': 'django.db.backends.mysql', 'NAME': 'inserv'...}
}

DATABASE_ROUTERS = ['AccWeeklyNursingReport.routers.WnrRouter',
'AccWeeklyNursingReport.routers.AccStaffRouter',
'AccWeeklyNursingReport.routers.AccInservRouter']

=end settings.py===

The following is the output example

C:\all\django\AccWeeklyNursingReport>mysqladmin -f drop  accstaff
Database "accstaff" dropped

C:\all\django\AccWeeklyNursingReport>mysqladmin -f create  accstaff

C:\all\django\AccWeeklyNursingReport>python manage.py  syncdb 
--database=accstaff
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff sessions
allow syncdb for WnrRouter accstaff wnrapp
allow syncdb for WnrRouter accstaff wnrapp
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff sessions
allow syncdb for WnrRouter accstaff wnrapp
allow syncdb for WnrRouter accstaff wnrapp
Creating tables ...
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff contenttypes
allow syncdb for WnrRouter accstaff contenttypes
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

C:\all\django\AccWeeklyNursingReport>echo DONE
DONE

-- 
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/DCD75728F460F14586086EA606E83082E71E861F%40ACEVXCHMBX1001.ADVENTISTCORP.NET.
For more options, visit https://groups.google.com/groups/opt_out.


routers.py
Description: routers.py


Re: Django 1.6 transactions witn multiple databases

2013-11-08 Thread Vaal
Thx!
How have I missed this ...
пятница, 8 ноября 2013 г., 9:47:22 UTC+4 пользователь akaariai написал:
>
> On Thursday, November 7, 2013 3:36:17 PM UTC+2, Vaal wrote:
>>
>> Hi
>> How to be in 1.6 with queries that involve multiple databases?
>> Previously recommended to create custom TransactionMiddleware. It was 
>> convenient. Now TransactionMiddleware is deprecated.
>>
>
> You can set ATOMIC_REQUESTS per database.
>

-- 
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/ae42b5ac-7c81-4fe5-94a9-68b26b2ea27c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django 1.6 transactions witn multiple databases

2013-11-07 Thread akaariai
On Thursday, November 7, 2013 3:36:17 PM UTC+2, Vaal wrote:
>
> Hi
> How to be in 1.6 with queries that involve multiple databases?
> Previously recommended to create custom TransactionMiddleware. It was 
> convenient. Now TransactionMiddleware is deprecated.
>

You can set ATOMIC_REQUESTS per database.

-- 
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/404f3556-5d44-4325-a47f-ae36cfd5cd3c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django 1.6 transactions witn multiple databases

2013-11-07 Thread Vaal
err
queries = requests

-- 
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/4cd3f9fe-c4a5-4e7d-a77f-b781b06410f7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Django 1.6 transactions witn multiple databases

2013-11-07 Thread Vaal
Hi
How to be in 1.6 with queries that involve multiple databases?
Previously recommended to create custom TransactionMiddleware. It was 
convenient. Now TransactionMiddleware is deprecated.

-- 
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/b01608ac-2eff-4409-ad69-eae35b8cf59a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: multiple databases and syncdb problem

2013-10-30 Thread Tom Evans
On Tue, Oct 29, 2013 at 9:35 PM, Simon Charette <charett...@gmail.com> wrote:
> syncdb defaults to syncing the 'default' database when no --database is
> specified.
>
> Try specifying which database to synchronize, with the --database=inserv
> flag in your case.
>

syncdb will only synch one DB at a time, and as Simon says, it will
default to 'default' if you do not specify a database. If you have
multiple databases, you need to call syncdb once for each of them.

A warning, if you have South installed, syncdb gains a '--all'
argument; this does not synch to all databases, it synchs all apps,
even migrated ones, which is probably not what you want.

Cheers

Tom

-- 
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/CAFHbX1LBNQEGgyrBvP%3DUy6rDnA1-0tnDY_urRs%2BcGz%2ByiSHGSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: multiple databases and syncdb problem

2013-10-29 Thread Simon Charette
syncdb defaults to syncing the 'default' database when no --database is 
specified
.

Try specifying which database to synchronize, with the --database=inserv 
flag in your case.

Le mardi 29 octobre 2013 16:52:15 UTC-4, fred a écrit :
>
>  I can syncdb OK if I don’t add allow_syncdb to my router, but if I add 
> the allow_syncdb to the router, only my default db is synced.  Any idea 
> what I’m doing wrong, code is:
>
>  
>
> def *allow_syncdb*(*self*, db, model):
>
> print *'allow syncdb for* Inserv Router'*, db, 
> model._meta.app_label
>
> return db==*'inserv'* and model._meta.app_label == *'inserv'*
>
>  
>  

-- 
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/48432761-428b-4e17-80d6-05f6c01de318%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


multiple databases and syncdb problem

2013-10-29 Thread Sells, Fred
I can syncdb OK if I don't add allow_syncdb to my router, but if I add the 
allow_syncdb to the router, only my default db is synced.  Any idea what I'm 
doing wrong, code is:

def allow_syncdb(self, db, model):
print 'allow syncdb for* Inserv Router', db, 
model._meta.app_label
return db=='inserv' and model._meta.app_label == 'inserv'

-- 
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/DCD75728F460F14586086EA606E83082E71DE597%40ACEVXCHMBX1001.ADVENTISTCORP.NET.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Managing transactions using multiple databases

2013-07-08 Thread Leandro Boscariol
Amazing work Christophe, congrats!
Lot's of new cool stuff being added to 1.6, looking forward to it.

Regarding the nested xact context managers, let's say something that I
don't like happened and I want to abort everything:

with xact(using=db1):
with xact(using=db2):
obj1 = Ob1.save(using=db1)
obj2 = Obj2.save(using=db2)
if not_cool:
raise Rollback

I'll raise Rollback since this is the way to force a rollback, as described
in the README.
But, this will roll back only whatever happened in the inner context
manager, thus obj1 will still exist, right?

Is there a way to make the Rollback reach the outer xact?
You wrote in a previous email that an exception will abort both, so
something like this should be the solution? (I have not tested):

try:
with xact(using=db1):
with xact(using=db2):
obj1 = Ob1.save(using=db1)
obj2 = Obj2.save(using=db2)
if not_cool:
raise Exception
except Exception:
return False
return True


Cheers,
Leandro


On 6 July 2013 16:44, Christophe Pettus  wrote:

>
> On Jul 6, 2013, at 8:58 PM, Leandro Boscariol wrote:
> > And also thanks for mentioning xact, I wasn't aware of that!
>
> Full disclosure: I wrote it. :)  In 1.6, the new atomic() decorator /
> context manager is the way to go, but xact() works fine for now!
>
> --
> -- Christophe Pettus
>x...@thebuild.com
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/WJUIVH2abjo/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Managing transactions using multiple databases

2013-07-06 Thread Christophe Pettus

On Jul 6, 2013, at 8:58 PM, Leandro Boscariol wrote:
> And also thanks for mentioning xact, I wasn't aware of that!

Full disclosure: I wrote it. :)  In 1.6, the new atomic() decorator / context 
manager is the way to go, but xact() works fine for now!

--
-- Christophe Pettus
   x...@thebuild.com

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Managing transactions using multiple databases

2013-07-06 Thread Leandro Boscariol
Well, even though without true two-phase commit, for now that will do, 
thanks.

And also thanks for mentioning xact, I wasn't aware of that!

Cheers,
Leandro

On Saturday, July 6, 2013 10:41:11 AM UTC-3, Christophe Pettus wrote:
>
>
> On Jul 6, 2013, at 2:54 PM, Leandro Boscariol wrote: 
>
> > How can I do a transaction management in both databases at the same 
> time? Is that even possible? 
>
> You can certainly nest the transaction context managers (atomic() in 1.6+, 
> or you can use xact() in 1.5 and earlier): 
>
>with xact(using=DATABASE1): 
>   with xact(using=DATABASE2): 
>  things 
>
> If an exception occurs, it will rollback both; if it exits normally, it 
> will commit both.  Note that this isn't true two-phase commit; it's 
> perfectly possible for the inner transaction to successfully commit but the 
> outer one to fail.  If you want proper two-phase commit, you'll (at the 
> moment, at least) have to roll your own. 
>
> -- 
> -- Christophe Pettus 
>x...@thebuild.com  
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Managing transactions using multiple databases

2013-07-06 Thread Christophe Pettus

On Jul 6, 2013, at 2:54 PM, Leandro Boscariol wrote:

> How can I do a transaction management in both databases at the same time? Is 
> that even possible?

You can certainly nest the transaction context managers (atomic() in 1.6+, or 
you can use xact() in 1.5 and earlier):

   with xact(using=DATABASE1):
  with xact(using=DATABASE2):
 things

If an exception occurs, it will rollback both; if it exits normally, it will 
commit both.  Note that this isn't true two-phase commit; it's perfectly 
possible for the inner transaction to successfully commit but the outer one to 
fail.  If you want proper two-phase commit, you'll (at the moment, at least) 
have to roll your own.

--
-- Christophe Pettus
   x...@thebuild.com

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Managing transactions using multiple databases

2013-07-06 Thread Leandro Boscariol
Hello,

During the design of a project, I came across a situation where I will have 
2 databases.
Not a big deal, it is very well documented in Django 
docs<https://docs.djangoproject.com/en/1.5/topics/db/multi-db/>
.

Dealing with 
transactions<https://docs.djangoproject.com/en/1.5/topics/db/transactions/>even 
when having multiple databases is also trivial, simply select which 
one the transaction is about.

At a given point, I'll have to interact with both databases in the same 
view.
Consider the snippet below as an example (not tested, nor this is what I 
intend to do):

@transaction.commit_manually()  # using='db1' or using='db2' or none??
def my_view(request):
try:
obj1 = MyObject1()
obj1.data = request.POST.get('data')
obj1.save(using='db1')
obj2 = MyObject2()
obj2.obj1_id = obj1id
obj2.save(using='db2')
except:
transaction.rollback()
else:
transaction.commit()
...


I didn't find any mention in the docs or in this list related to this, so 
here is my question:

How can I do a transaction management in both databases at the same time? 
Is that even possible?


Thanks in advance for your help.
Leandro.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to create a Django Group in case of multiple databases.

2013-02-09 Thread Bill Freeman
It is wrong.  As Tom pointed out, you must use:

def save(self, *args, **kwargs):

And then, wherever you call the super class save method, use:

super(ModelName, self).save(*args, **kwargs)

You also don't need the first setting of modified_date_time, since the
second will happen whether or not self.id is set.

Further, the code would be simpler to understand and maintain if, instead
of touching them here, you used the auto_now=True option on the
modified_date_time field of the model and the auto_now_add=True option on
the created_date_time field of the model.  (I don't remember whether, in
your original post, you had some reason to, for example, store these times
in a different timezone  than Django's and the database's configurations.)

Bill

On Fri, Feb 8, 2013 at 11:20 AM, laxmikant ratnaparkhi
wrote:

> I have not trimmed traceback. This is ouput came on python manage.py shell.
>
> And one more thing I modified save method This looks like this:
>
>def save(self):
> if not self.id:
> self.created_date_time = datetimeToUTC()
> self.modified_date_time = datetimeToUTC()
> self.modified_date_time = datetimeToUTC()
> super(ModelName, self).save()
> if not self.uid:
> self.uid = idmaptoalpha.getUID(self.id)
> super(ModelName, self).save()
>
>  Can you plz tell me if anything is wrong in it.
>
> Thanks again.
>
> *N.B.:*But I have not  modified method for Django's Group  Table. This is
> only for the new Classed I created.
>
> Regards,
> Laxmikant
>
>
> On Thu, Feb 7, 2013 at 11:49 PM, Tom Evans wrote:
>
>> On Thu, Feb 7, 2013 at 12:16 PM, laxglx  wrote:
>> >
>> > Hello Everybody,
>> >
>> > I'm going to create a Group using Django Group.
>> >
>> > I have two databases one is "master" and another is "slave"
>> > In master I created a user and group as usual.
>> >
>> > And in slave database I tried like this:
>> >
>> >
>>  Group.objects.db_manager('slave').create(name="grp1")
>> >
>> > This returned an error :
>> >
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> >   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
>> line
>> > 138, in create
>> > return self.get_query_set().create(**kwargs)
>> >   File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
>> line
>> > 358, in create
>> > obj.save(force_insert=True, using=self.db)
>> > TypeError: save() got an unexpected keyword argument 'force_insert'
>>
>> Have you trimmed this traceback?
>>
>> >
>> > I also tried as follows, but got error :
>> >
>>  g = Group()
>>  g.name = "grp1"
>>  g.save(using='slave')
>> > Traceback (most recent call last):
>> >   File "", line 1, in 
>> > TypeError: save() got an unexpected keyword argument 'using'
>> >
>>
>> It looks like you have overwritten the save() method on the model you
>> are trying to save, and have not given it a method signature capable
>> of accepting the necessary arguments that save() is expected to
>> handle.
>>
>> I say 'looks like', since I think you have obliterated the parts of
>> the traceback that would tell me…
>>
>> save() takes many arguments. If you are not specifying any additional
>> arguments for your save() method, then it should look like so:
>>
>> def save(self, *args, **kwargs):
>>
>> This protects you from having to change the method if more arguments
>> are added in later versions of django, eg when the 'using' argument
>> was added in 1.2.
>>
>> As usual, the docs have canonical instructions on how to override
>> model methods like save():
>>
>>
>> https://docs.djangoproject.com/en/1.4/topics/db/models/#overriding-model-methods
>>
>> Cheers
>>
>> Tom
>>
>> --
>> 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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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

Re: How to create a Django Group in case of multiple databases.

2013-02-08 Thread laxmikant ratnaparkhi
I have not trimmed traceback. This is ouput came on python manage.py shell.

And one more thing I modified save method This looks like this:

   def save(self):
if not self.id:
self.created_date_time = datetimeToUTC()
self.modified_date_time = datetimeToUTC()
self.modified_date_time = datetimeToUTC()
super(ModelName, self).save()
if not self.uid:
self.uid = idmaptoalpha.getUID(self.id)
super(ModelName, self).save()

 Can you plz tell me if anything is wrong in it.

Thanks again.

*N.B.:*But I have not  modified method for Django's Group  Table. This is
only for the new Classed I created.

Regards,
Laxmikant


On Thu, Feb 7, 2013 at 11:49 PM, Tom Evans  wrote:

> On Thu, Feb 7, 2013 at 12:16 PM, laxglx  wrote:
> >
> > Hello Everybody,
> >
> > I'm going to create a Group using Django Group.
> >
> > I have two databases one is "master" and another is "slave"
> > In master I created a user and group as usual.
> >
> > And in slave database I tried like this:
> >
> >
>  Group.objects.db_manager('slave').create(name="grp1")
> >
> > This returned an error :
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line
> > 138, in create
> > return self.get_query_set().create(**kwargs)
> >   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
> > 358, in create
> > obj.save(force_insert=True, using=self.db)
> > TypeError: save() got an unexpected keyword argument 'force_insert'
>
> Have you trimmed this traceback?
>
> >
> > I also tried as follows, but got error :
> >
>  g = Group()
>  g.name = "grp1"
>  g.save(using='slave')
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > TypeError: save() got an unexpected keyword argument 'using'
> >
>
> It looks like you have overwritten the save() method on the model you
> are trying to save, and have not given it a method signature capable
> of accepting the necessary arguments that save() is expected to
> handle.
>
> I say 'looks like', since I think you have obliterated the parts of
> the traceback that would tell me…
>
> save() takes many arguments. If you are not specifying any additional
> arguments for your save() method, then it should look like so:
>
> def save(self, *args, **kwargs):
>
> This protects you from having to change the method if more arguments
> are added in later versions of django, eg when the 'using' argument
> was added in 1.2.
>
> As usual, the docs have canonical instructions on how to override
> model methods like save():
>
>
> https://docs.djangoproject.com/en/1.4/topics/db/models/#overriding-model-methods
>
> Cheers
>
> Tom
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to create a Django Group in case of multiple databases.

2013-02-07 Thread Tom Evans
On Thu, Feb 7, 2013 at 12:16 PM, laxglx  wrote:
>
> Hello Everybody,
>
> I'm going to create a Group using Django Group.
>
> I have two databases one is "master" and another is "slave"
> In master I created a user and group as usual.
>
> And in slave database I tried like this:
>
>
 Group.objects.db_manager('slave').create(name="grp1")
>
> This returned an error :
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line
> 138, in create
> return self.get_query_set().create(**kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
> 358, in create
> obj.save(force_insert=True, using=self.db)
> TypeError: save() got an unexpected keyword argument 'force_insert'

Have you trimmed this traceback?

>
> I also tried as follows, but got error :
>
 g = Group()
 g.name = "grp1"
 g.save(using='slave')
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: save() got an unexpected keyword argument 'using'
>

It looks like you have overwritten the save() method on the model you
are trying to save, and have not given it a method signature capable
of accepting the necessary arguments that save() is expected to
handle.

I say 'looks like', since I think you have obliterated the parts of
the traceback that would tell me…

save() takes many arguments. If you are not specifying any additional
arguments for your save() method, then it should look like so:

def save(self, *args, **kwargs):

This protects you from having to change the method if more arguments
are added in later versions of django, eg when the 'using' argument
was added in 1.2.

As usual, the docs have canonical instructions on how to override
model methods like save():

https://docs.djangoproject.com/en/1.4/topics/db/models/#overriding-model-methods

Cheers

Tom

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




How to create a Django Group in case of multiple databases.

2013-02-07 Thread laxglx

Hello Everybody,

I'm going to create a Group using Django Group. 

I have two databases one is "master" and another is "slave" 
In master I created a user and group as usual. 

And in slave database I tried like this:


*>>> Group.objects.db_manager('slave').create(name="grp1")*

This returned an error : 

*Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 
138, in create
return self.get_query_set().create(**kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 
358, in create
obj.save(force_insert=True, using=self.db)
TypeError: save() got an unexpected keyword argument 'force_insert'*

I also tried as follows, but got error :

*>>> g = Group()
>>> g.name = "grp1"
>>> g.save(using='slave')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: save() got an unexpected keyword argument 'using'
*

Thanks in advance...


Laxmikant

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Trying to find something in multiple databases... Confused...

2012-06-19 Thread Melvyn Sopacua
On 19-6-2012 9:46, Laurence MacNeill wrote:
> On Monday, June 18, 2012, Melvyn Sopacua wrote:
> 
>> On 18-6-2012 9:52, Laurence MacNeill wrote:
>>> well -- I hit the wrong key and posted that before I was finished
>> typing...
>>>
>>> here's what's in my views.py file:
>>> def index(request)
>>>  current_username = os.environ['REMOTE_USER']
>>
>> And you're sure this works? Try:
>>  return django.shortcuts.render_to_response(current_username)
>>
>> here to verify it's coming through. Normally, the authenticated username
>> would be part of the request dictionary.
> 
> 
> 
> Yeah, it's not working...  How do I get the user-name from the request
> dictionary?  request.REMOTE_USER or somthing like that?
> 
> It's not using Django for the user-validation, though...  When someone logs
> into the site, they get redirected to a page that validates them.  This is
> controled by the Apache web-server itself -- if they try to access any
> document served by Apache, and they don't have a cookie on their computer,
> they're redirected to a different page where they enter their user ID and
> password, then are sent back to the original page.  The user-id is then
> stored in a linux environment variable called REMOTE_USER.  So I figured
> the only way to access it was via the os.environ method.

I get the feeling you're mixing and matching server-side programming
languages. If you're using any variation of basic HTTP authentication,
then the operating system environment isn't a factor, but the CGI
environment is, which gets set "somewhere" based on module
implementation. Maybe you think it's an environment variable, because
Php stores it in $_SERVER. Or because you use plain CGI scripts and for
those CGI environment equals OS environment. If that's the case, then
what you're looking for is this:
https://docs.djangoproject.com/en/1.4/howto/auth-remote-user/

HTTP protocol details as background:
What really happens with HTTP authentication that way, is that the
server sends a 401 Authorization Required response to the browser.  The
user then enters username and password and if the server finds this
combination to be correct, it returns a redirect or shows the requested
page. If not, the server sends a 403 Forbidden.
Per CGI 1.1 specification [1], the server shall set the variable
REMOTE_USER in the CGI environment if it successfully authenticated a user.

[1] http://tools.ietf.org/html/rfc3875#section-4.1.11
-- 
Melvyn Sopacua

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Trying to find something in multiple databases... Confused...

2012-06-19 Thread Laurence MacNeill
Right -- different tables in the same database, of course...  Thanks.

L.


On Monday, June 18, 2012, Daniel Roseman wrote:

> On Monday, 18 June 2012 08:40:53 UTC+1, Laurence MacNeill wrote:
>>
>> Ok, I'm a total django noob here, so I am probably doing this wrong...
>> But here goes...
>>
>> When someone comes to my django app's root (index), I need to verify
>> their user-name (which is stored in a Linux environment variable).  Based
>> on where (or if) I find their user-name, I want to send them to one of
>> three different pages -- if I don't find them in any database, I want to
>> add them to a given database, then send them to a page.
>>
>> So here's what I have in my views.py file:
>> def index(request)
>>  current_username = os.environ['REMOTE_USER']
>>
>>
> So Melvyn has answered your question, but a quick note on terminology:
> what you've got there are separate *database tables*, or separate *Django
> models* -- not separate databases. Multiple databases is a whole different
> question, which you really don't want to get into as a newbie (or, indeed,
> at all if possible).
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/jSuHg6H4amoJ.
> To post to this group, send email to 
> django-users@googlegroups.com<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> 'django-users%2bunsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Trying to find something in multiple databases... Confused...

2012-06-19 Thread Laurence MacNeill
On Monday, June 18, 2012, Melvyn Sopacua wrote:

> On 18-6-2012 9:52, Laurence MacNeill wrote:
> > well -- I hit the wrong key and posted that before I was finished
> typing...
> >
> > here's what's in my views.py file:
> > def index(request)
> >  current_username = os.environ['REMOTE_USER']
>
> And you're sure this works? Try:
>  return django.shortcuts.render_to_response(current_username)
>
> here to verify it's coming through. Normally, the authenticated username
> would be part of the request dictionary.



Yeah, it's not working...  How do I get the user-name from the request
dictionary?  request.REMOTE_USER or somthing like that?

It's not using Django for the user-validation, though...  When someone logs
into the site, they get redirected to a page that validates them.  This is
controled by the Apache web-server itself -- if they try to access any
document served by Apache, and they don't have a cookie on their computer,
they're redirected to a different page where they enter their user ID and
password, then are sent back to the original page.  The user-id is then
stored in a linux environment variable called REMOTE_USER.  So I figured
the only way to access it was via the os.environ method.



>
> Almost correct:
> if student is not None :
> # the student.html template will now have a variable named student
> # which is the student object you fetched
> return render_to_response('ta/student.html', student=student)
> elif instructor is not None :
> #etc


Ahh, ok -- that makes sense...  Thanks...

L.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Kurtis Mullins
On Mon, Jun 18, 2012 at 1:45 PM, Dennis Lee Bieber <wlfr...@ix.netcom.com>wrote:
>
>
> First, is everybody on the same page (terminology)... (Independent
> of Django)
>
>First is: multiple database engines (SQLite3, MySQL, Access/JET,
> etc.). Working across multiple engines is never easy -- one typically
> has to implement the equivalent of "select ... from ... join ..." in
> program code -- that is, fetch records from each engine and merge them
> by hand to produce a result set.
>
>Second is: multiple databases within an engine. Database engines are
> designed to allow for separate databases with independent user access --
> a personnel/payroll database would not be accessible by the parts
> order/tracking system, even when both are stored on the same database
> engine/server -- however, an application /might/ be permitted such an
> odd mix if the user authorization permits access to both databases. For
> SQLite3 and Access/JET, a database is a single file (no particular
> extension for SQLite3, Access used to use .MDB) and an application
> typically opens/connects to just one of these -- but means are available
> to "link" a second into visibility.
>
>Third: a database, as defined in #2, contains multiple relations
> (tables) which may or may not be interconnected by foreign key
> references (in relational database theory, a relation is a single table
> in which the data of each tuple (record) is related to a unique key for
> the tuple; relation does NOT refer to linkages by foreign keys between
> tables).


I believe, by reading the context, it was pretty obvious he meant databases
(definition #2)  being managed under multiple database management systems,
without regards to their specified database engine.

By the way, MySQL is not a database engine -- it is a database management
system. MyISAM and InnoDB would be database engines.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Kurtis Mullins
>
> On Mon, Jun 18, 2012 at 9:30 AM, Daniel Roseman 
>  wrote:

There are certain "advanced" features of Django - multiple DBs, model
> subclassing, that sort of thing


I feel there's quite a few problems that would be relatively unsolvable
without model subclassing. At least in any efficient way.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Daniel Roseman
On Monday, 18 June 2012 13:16:55 UTC+1, lawgon wrote:
>
> On Mon, 2012-06-18 at 05:12 -0700, Daniel Roseman wrote: 
> > Multiple databases is a whole different 
> > question, which you really don't want to get into as a newbie (or, 
> > indeed, 
> > at all if possible). 
>
> could you elaborate on this - I was thinking on getting into multiple 
> databases and would appreciate your take. 
> -- 
> regards 
> Kenneth Gonsalves 
>
>
Oh, I'm just being my usual crotchety self. There are certain "advanced" 
features of Django - multiple DBs, model subclassing, that sort of thing - 
that I tend to feel we'd be better off without. But I'm almost certainly 
being unfair, there is definitely a use case for multiple DBs: it's when 
people start trying to use it for things like dynamic multitenancy that I 
start to despair.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Hdn_97GiNjAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread kenneth gonsalves
On Mon, 2012-06-18 at 05:12 -0700, Daniel Roseman wrote:
> Multiple databases is a whole different 
> question, which you really don't want to get into as a newbie (or,
> indeed, 
> at all if possible). 

could you elaborate on this - I was thinking on getting into multiple
databases and would appreciate your take.
-- 
regards
Kenneth Gonsalves

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Daniel Roseman
On Monday, 18 June 2012 08:40:53 UTC+1, Laurence MacNeill wrote:
>
> Ok, I'm a total django noob here, so I am probably doing this wrong...  
> But here goes...
>
> When someone comes to my django app's root (index), I need to verify their 
> user-name (which is stored in a Linux environment variable).  Based on 
> where (or if) I find their user-name, I want to send them to one of three 
> different pages -- if I don't find them in any database, I want to add them 
> to a given database, then send them to a page.
>
> So here's what I have in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']
>
>
So Melvyn has answered your question, but a quick note on terminology: what 
you've got there are separate *database tables*, or separate *Django 
models* -- not separate databases. Multiple databases is a whole different 
question, which you really don't want to get into as a newbie (or, indeed, 
at all if possible).
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jSuHg6H4amoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Melvyn Sopacua
On 18-6-2012 9:52, Laurence MacNeill wrote:
> well -- I hit the wrong key and posted that before I was finished typing... 
> 
> here's what's in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']

And you're sure this works? Try:
 return django.shortcuts.render_to_response(current_username)

here to verify it's coming through. Normally, the authenticated username
would be part of the request dictionary.

> This should provide me with their username (yes I do have 'import os' at 
> the top of the file)...
> 
> Now, after I get their username I want to do something like this (but I'm 
> not sure how to write in django -- so I've put ## around the pseudo-code)
>  try:
>  student = Student.objects.get(student_name=current_username)
>  except (#can't find it in Student database, but I don't know what code 
> to put here#)

It's in tutorial part 3:
https://docs.djangoproject.com/en/1.4/intro/tutorial03/#raising-404

except Student.DoesNotExist:
   student = None

>  #here's where I'm not sure how to continue -- I want to do something 
> like this#
>  #if student is defined#
>   return render_to_response('ta/student.html', student)

Almost correct:
if student is not None :
 # the student.html template will now have a variable named student
 # which is the student object you fetched
 return render_to_response('ta/student.html', student=student)
elif instructor is not None :
 #etc

-- 
Melvyn Sopacua

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
well -- I hit the wrong key and posted that before I was finished typing... 

here's what's in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

This should provide me with their username (yes I do have 'import os' at 
the top of the file)...

Now, after I get their username I want to do something like this (but I'm 
not sure how to write in django -- so I've put ## around the pseudo-code)
 try:
 student = Student.objects.get(student_name=current_username)
 except (#can't find it in Student database, but I don't know what code 
to put here#)
 try:
 instructor = 
Instructor.objects.get(instructor_name=current_username)
 except (#can't find it in Instructor database, but I don't know 
what code to put here#)
   try:
administrator = 
Administrator.objects.get(administrator_name=current_username)
   except (#fail condition - can't find current_username in 
Administrator database, but I don't know what code to put here#)
#because we failed to find it in any database, we 
assume it's a student and add it
student = Student(student_name=current_username)
student.save
 #here's where I'm not sure how to continue -- I want to do something 
like this#
 #if student is defined#
  return render_to_response('ta/student.html', student)
 #else if instructor is defined#
  return render_to_response('ta/instructor.html', instructor)
 #else if administrator is defined#
  return render_to_response('ta/administrator.html', administrator)
#end of my code#

So -- can someone please help me fill in the missing code above?  I've been 
searching for hours, but I just can't seem to hit on the correct 
search-terms to get done what I want here...

Thanks,
Laurence MacNeill
Mableton, Georgia, USA


On Monday, June 18, 2012 3:40:53 AM UTC-4, Laurence MacNeill wrote:
>
> Ok, I'm a total django noob here, so I am probably doing this wrong...  
> But here goes...
>
> When someone comes to my django app's root (index), I need to verify their 
> user-name (which is stored in a Linux environment variable).  Based on 
> where (or if) I find their user-name, I want to send them to one of three 
> different pages -- if I don't find them in any database, I want to add them 
> to a given database, then send them to a page.
>
> So here's what I have in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rVfs691Nk0AJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
Ok, I'm a total django noob here, so I am probably doing this wrong...  But 
here goes...

When someone comes to my django app's root (index), I need to verify their 
user-name (which is stored in a Linux environment variable).  Based on 
where (or if) I find their user-name, I want to send them to one of three 
different pages -- if I don't find them in any database, I want to add them 
to a given database, then send them to a page.

So here's what I have in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/89ghQfC_J0IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Multiple databases or Redis/Stats/Graphite/Loggly

2012-05-02 Thread Jean-Mark
Hi all,
 I'm working on an app that will store gps coordinates from devices. That 
information will come in every 5 or so minutes of each hour. So it's alot 
of data. Any recommendations on how I should store this? Do I use multiple 
databases and use say MongoDB or Couch for the storage of the points or do 
I use a solution like Redis / Graphite/Stats or Loggly?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bzE4dTWSdB0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ModelChoiceField with multiple databases

2011-12-21 Thread Brian Craft
Is there an easy way to use a ModelChoiceField with multiple databases?

The only thing I've seen that looks promising is overriding the form
__init__ and setting the queryset for the field. Seems kinda clunky.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-24 Thread Jianbao Tao
Reinout,

Thanks so much for your help. I think I have figured out the solution. I
posted it on
https://groups.google.com/forum/?hl=en#!topic/django-users/zwMWNdIqB3A.

Please take a look.

Jianbao

On Wed, Aug 24, 2011 at 10:13 AM, Reinout van Rees wrote:

> On 24-08-11 17:57, Jianbao Tao wrote:
>
>> Now './manage.py syncdb' can run through with no problems. However, it
>> doesn't create the database 'test.sqlite', which means the models in the
>> app, books, are still installed in the default database.
>>
>>
> That's in the django docs: syncdb only managed the main default database by
> default. You'll have to call syncdb on the second database separately.
>
> Often the second database is an existing one that django shouldn't touch,
> that's why the default is that way.
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
> --
> 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 django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Tips for setting up multiple databases routing in Django

2011-08-24 Thread Jim
First of all, I would like to thank Reinout van Rees (
http://reinout.vanrees.org/) for his helpful suggestions. 

Suppose you have two databases, 'default' and 'test', and one app, 'books'. 
And you want to store the models in books in the database 'test'. 

According to the guide from Django 
doc, 
you may have something like this in your settings.py:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/path/to/default.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
'test': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/path/to/test.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}


And a routing file, say dbrouting.py, which has something like this:

class DBRouter(object):
def db_for_read(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test' # dbName is a name in settings.DATABASES
else:
dbName = None
return dbName

def db_for_write(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
return dbName

def allow_relation(self, obj1, obj2, **hints):
label1 = obj1._meta.app_label
label2 = obj2._meta.app_label
if label1 == label2:
return True
return None

def allow_syncdb(self, db, model):
# db is a string of database name.
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
if dbName == db:
return True
else:
return False


Now, here is the important stuff. If you don't have the database file 
test.sqlite yet, you must create it first before you enable the database 
routing. Use the following command to do this:

./manage.py syncdb --database=test

With this step, Django will initialize the database, including creating some 
required tables (such as django_content_type). In the routing scheme, only 
models from the app books can access the database 'test'. That means that 
even Django cannot get in the database and make the necessary setups 
including creating some necessary tables. Once you have initialized the 
database, you can enable the routing scheme.

To sum up, here are the steps I recommend if you want to create a database 
to store data from certain models.

   1. Add that new database to settings.py.
   2. Make sure that the database routing is disabled. (To disable the 
   database routing, just comment out the DATABASE_ROUTERS setting in the 
   settings.py file.)
   3. Initialize your new database as shown above.
   4. Enable database routing (by enabling the DATABASE_ROUTERS setting in 
   the settings.py file).
   5. Run ./manage.py syncdb --database= to create 
   tables for your models.
   
In the above steps, I assume you have created your models and database 
routers properly.

That's it.

BTW, I am new to Django. So, if I am missing anything above or having 
anything misleading, please do correct me. Thank you very much.
 



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/3CnRHQefMHAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 24-08-11 17:57, Jianbao Tao wrote:

Now './manage.py syncdb' can run through with no problems. However, it
doesn't create the database 'test.sqlite', which means the models in the
app, books, are still installed in the default database.



That's in the django docs: syncdb only managed the main default database 
by default. You'll have to call syncdb on the second database separately.


Often the second database is an existing one that django shouldn't 
touch, that's why the default is that way.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-24 Thread Jianbao Tao
Thank you, Reinout.

I changed the definition of 'allow_syncdb' to the following:

def allow_syncdb(self, db, model):
# db is a string of database name.
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
if dbName == db:
return True
else:
return None


Now './manage.py syncdb' can run through with no problems. However, it
doesn't create the database 'test.sqlite', which means the models in the
app, books, are still installed in the default database.

Also, I am using django v1.3.

In addition, about the *two* things you mentioned, how can I test for that?
It seems all the functions defined in the class DBRouter are called
internally by django. I don't know how to make django print something so
that I know what's going on when django calls those function.

Again, thank you very much.


On Wed, Aug 24, 2011 at 2:15 AM, Reinout van Rees wrote:

> On 23-08-11 01:31, Jim wrote:
>
>> def allow_syncdb(self, db, model):
>> # db is a string of database name.
>> label = model._meta.app_label
>> if label == 'books':
>> dbName = 'test'
>> else:
>> dbName = None
>> return dbName == db
>>
>
> I'd do the "if" part as follows:
>
>if label == 'books':
>if db == 'test':
>return True
>return False
>if db == 'test':
>return False
>return None  # None means 'no opinion'.
>
> iirc allow_syncdb() ought to return True/False to indicate whether a
> certain model should be synced to a certain database. So you need to make
> sure *two* things:
>
> - Your special models only end up in your special database and not in
> another.
>
> - Other models (like the django_content_type table that gives you
> problems!) should not end up in your special deatabase.
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> 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 django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 23-08-11 01:31, Jim wrote:

django.db.utils.DatabaseError: no such table: django_content_type


Which django version, btw? Early 1.2 beta versions had a bug:

https://code.djangoproject.com/ticket/12999


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-24 Thread Reinout van Rees

On 23-08-11 01:31, Jim wrote:

 def allow_syncdb(self, db, model):
 # db is a string of database name.
 label = model._meta.app_label
 if label == 'books':
 dbName = 'test'
 else:
 dbName = None
 return dbName == db


I'd do the "if" part as follows:

if label == 'books':
if db == 'test':
return True
return False
if db == 'test':
return False
return None  # None means 'no opinion'.

iirc allow_syncdb() ought to return True/False to indicate whether a 
certain model should be synced to a certain database. So you need to 
make sure *two* things:


- Your special models only end up in your special database and not in 
another.


- Other models (like the django_content_type table that gives you 
problems!) should not end up in your special deatabase.




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problems on using multiple databases

2011-08-23 Thread Jim
Still stuck on this problem. Can anybody help me out, please? It would be 
much appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/K9twgNZcE4IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problems on using multiple databases

2011-08-22 Thread Jim
Hello folks,

I am learning to set up multiple databases routing in Django.

Before I started, I had everything working properly. Then, I wrote 
dbrouter.py under the site directory, basically by copying the example in the 
Django document about using multiple 
databases<https://docs.djangoproject.com/en/dev/topics/db/multi-db/>. 
Here is what's in dbrouter.py:
#
class DBRouter(object):
def db_for_read(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test' # dbName is a name in settings.DATABASES
else:
dbName = None
return dbName

def db_for_write(self, model, **hints):
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
return dbName

def allow_syncdb(self, db, model):
# db is a string of database name.
label = model._meta.app_label
if label == 'books':
dbName = 'test'
else:
dbName = None
return dbName == db
#

As you can see from dbrouter.py, I have an app called books. 

Here is the DATABASES setting:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': dbPath + os.sep + 'default.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
'test': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': dbPath + os.sep + 'test.sqlite',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}


Then, I added the following setting to settings.py.
DATABASE_ROUTERS = [siteName + '.dbrouter.DBRouter']

Finally, I ran ./manage.py syncdb. And got these error messages:

>$ ./manage.py syncdb
Creating tables ...
Traceback (most recent call last):
  File "./manage.py", line 17, in 
execute_manager(settings)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/__init__.py",
 
line 438, in execute_manager
utility.execute()
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/__init__.py",
 
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/base.py",
 
line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/base.py",
 
line 220, in execute
output = self.handle(*args, **options)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/base.py",
 
line 351, in handle
return self.handle_noargs(**options)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
 
line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/core/management/sql.py",
 
line 190, in emit_post_sync_signal
interactive=interactive, db=db)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
 
line 172, in send
response = receiver(signal=self, sender=sender, **named)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
 
line 30, in create_permissions
ctype = ContentType.objects.get_for_model(klass)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/contrib/contenttypes/models.py",
 
line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 135, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/db/models/query.py",
 
line 378, in get_or_create
return self.get(**lookup), False
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/db/models/query.py",
 
line 344, in get
num = len(clone)
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/django/db/models/query.py",
 
line 82, in __len__
self._result_cache = list(self.iterator())
  File 
"/Users/jianbao/projects/tao.com/mysite/lib/python2.7/site-packages/dja

  1   2   3   >