Get all table names in a Django app

This will give you all of the table names, like the OP asks for: from django.apps import apps tables = [m._meta.db_table for c in apps.get_app_configs() for m in c.get_models()] This will give you all model names: from django.db import connection tables = connection.introspection.table_names() seen_models = connection.introspection.installed_models(tables) This will give you all of the model names … Read more

How to add column in ManyToMany Table (Django)

It’s very easy using django too! You can use through to define your own manytomany intermediary tables Documentation provides an example addressing your issue: Extra fields on many-to-many relationships class Person(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through=”Membership”) def __unicode__(self): return self.name class Membership(models.Model): person = … Read more

Generic many-to-many relationships

You can implement this using generic relationships by manually creating the junction table between message and recipient: from django.db import models from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType class Client(models.Model): city = models.CharField(max_length=16) # These aren’t required, but they’ll allow you do cool stuff # like “person.sent_messages.all()” to get all messages sent # by … Read more

How to query directly the table created by Django for a ManyToMany relation?

This is the many to many field instance: MyModel2.mymodel1 This is the intermediary table model: MyModel2.mymodel1.through This is the intermediary model manager: MyModel2.mymodel1.through.objects This returns a queryset for all intermediary models: MyModel2.mymodel1.through.objects.all() This part of django docs talk about through. You can make a through model yourself, else it is automatically generated.

SQLAlchemy ManyToMany secondary table with additional fields

You will have to switch from using a plain, many-to-many relationship to using an “Association Object”, which is basically just taking the association table and giving it a proper class mapping. You’ll then define one-to-many relationships to User and Community: class Membership(db.Model): __tablename__ = ‘community_members’ id = db.Column(‘id’, db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey(‘user.id’)) community_id … Read more

UnsupportedOperationException merge-saving many-to-many relation with hibernate and JPA

It is because of your Arrays.asList(roleProvider.findAll().get(0)) This creates an unmodifiable list (in fact, a non-resizable list). Hibernate seems to expect a modifiable list. Try using this instead: public void testAccountRole(){ Account returnedAccount = accountProvider.findAll().get(0); List<Role> list = new ArrayList<Role>(); list.add(roleProvider.findAll().get(0)); returnedAccount.setRoles(list); accountProvider.save(returnedAccount); } This solution won’t explain why exactly you got the other exception (might … Read more

Many-to-many mapping table

Do this on your DbContext OnModelCreating: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Recipe>() .HasMany(x => x.Members) .WithMany(x => x.Recipes) .Map(x => { x.ToTable(“Cookbooks”); // third table is named Cookbooks x.MapLeftKey(“RecipeId”); x.MapRightKey(“MemberId”); }); } You can do it the other way around too, it’s the same, just another side of the same coin: modelBuilder.Entity<Member>() .HasMany(x => … Read more

Symfony2-Doctrine: ManyToMany relation is not saved to database

Your Category entity is the inverse side of the relationship. Try changing addItems to look like this: public function addItem(\Ako\StoreBundle\Entity\Item $item) { $item->addCategory($this); $this->items[] = $item; } Note that I changed your plural names to singular, since you’re dealing with single entities, not collections.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)