shelman
shelman

Reputation: 13

Storing user music playlists for a website

I want to make a music playing website where users can save playlists of songs to be regenerated later. I'm kind of a newbie to sql, but it seems like databases are meant to hold fixed-length variables, whereas a user-generated playlist would be an arbitrary length. There are a couple ways I've thought of to handle this:

I feel like there's an easy third way I'm missing. I'm doing this in php, but if there's a super easy way using django I'd also be interested.

Upvotes: 1

Views: 897

Answers (2)

AR.
AR.

Reputation: 1955

How about this:

Playlists: list_id|title|owner_id
Songs: song_id|title|artist|album|year|length|style|whatevereelseyouwnattoadd
Songs_In_Lists: song_id|list_id

Third table just ties songs to playlists. otherwise there will be a lot of redundancy with song info if song goes to multiple playlists. The primary key for the third table will be on both columns. Same song goes to same list only once, so it works fine.

Upvotes: 2

zerkms
zerkms

Reputation: 254886

2 tables:

  1. Playlists. Fields: id | title | owner_id (reference to user.id)
  2. Songs. Fields: id | title | length | playlist_id (reference to playlist.id)

Upvotes: 2

Related Questions